class Game extends Phaser.State {

  init (stageName) {
    this.controls = this.game.controls;

    this.stageName = stageName;
  }

  create () {
    this.add.existing(new BackgroundPattern(this.game, BackgroundPattern.MOON));

    this._tilemap = this.add.tilemap('tilemaps');
    this._tilemap.setCollisionBetween(1, 144, true, 'test');
    this._tilemap.addTilesetImage('tileset');

    this._layer = this._tilemap.createLayer('test');

    this._heart = this.add.existing(new Character(this.game, 168, 32, Character.HEART));
    this._star = this.add.existing(new Character(this.game, 72, 32, Character.STAR));

    this._player = this._star;

    this.controls.spacebar.onUp.add(this._togglePlayerCharacter, this);
    this.controls.backspace.onUp.add(this._restartCharacters, this);

    this._star.animations.play('cheering');
  }

  update () {
    this.physics.arcade.collide(this._heart, this._star);
    this.physics.arcade.collide(this._star,  this._layer);
    this.physics.arcade.collide(this._heart, this._layer);

    this._heart.body.acceleration.x = 0;
    this._star.body.acceleration.x = 0;

    if (this.controls.left.isDown)
      this._player.walkLeft();
    else if (this.controls.right.isDown)
      this._player.walkRight();

    if (this.controls.up.isDown) {
      this._player.jump();
    }
    else {
      this._player.cancelPowerJump();
    }
  }

  // --------------------------------------------------------------------------

  _togglePlayerCharacter () {
    if (this._player.standing)
      this._player = this._player === this._heart ? this._star : this._heart;
  }

  _restartCharacters () {
    this._heart.reset(168, 32);
    this._star.reset(72, 32);
  }

}


import Character         from 'objects/Character';
import BackgroundPattern from 'objects/BackgroundPattern';

export default Game;

@@ -121,16 +121,85 @@
 ageName;
+%0A%0A    this._playerCharacter = null;%0A    this._idleCharacter   = null;
 %0A  %7D%0A%0A  
@@ -694,27 +694,56 @@
 is._
-player = this._star
+setupPlayableCharacters(this._star, this._heart)
 ;%0A%0A 
@@ -885,53 +885,8 @@
 is);
-%0A%0A    this._star.animations.play('cheering');
 %0A  %7D
@@ -1209,24 +1209,33 @@
 this._player
+Character
 .walkLeft();
@@ -1294,16 +1294,25 @@
 ._player
+Character
 .walkRig
@@ -1371,16 +1371,25 @@
 ._player
+Character
 .jump();
@@ -1424,16 +1424,25 @@
 ._player
+Character
 .cancelP
@@ -1545,16 +1545,168 @@
 ------%0A%0A
+  _setupPlayableCharacters(playerCharacter, idleCharacter) %7B%0A    this._playerCharacter = playerCharacter;%0A    this._idleCharacter = idleCharacter;%0A  %7D%0A%0A
   _toggl
@@ -1747,16 +1747,25 @@
 ._player
+Character
 .standin
@@ -1766,16 +1766,18 @@
 tanding)
+ %7B
 %0A      t
@@ -1785,73 +1785,82 @@
 is._
-player = this._player === this._heart ? this._star : this._heart;
+setupPlayableCharacters(this._idleCharacter, this._playerCharacter);%0A    %7D
 %0A  %7D

Improve character toggling logic.