问题
I'm trying to switch state with a collision. So when the player hits another sprite it should switch state, but it doesn't..
First I'm declaring the player and the enterDoor sprites under create:
:
playerSprite = this.game.add.sprite(50, 1700, 'player-front');
player = new Player(playerSprite);
this.game.physics.enable(player, Phaser.Physics.ARCADE);
enterDoor = this.game.add.sprite(332, 830, 'player-back');
playerDoor = new Player(enterDoor);
this.game.physics.enable(playerDoor, Phaser.Physics.ARCADE);
Then I'm trying to make the overlap under update:
:
this.game.physics.arcade.overlap(player, playerDoor, this.enterHouse, null, this);
And enterHouse is another function:
enterHouse: function() {
this.state.start('Menu');
}
What am I doin' wrong?
回答1:
So with the code above I wasn't able to get the overlap
to trigger at all. After disabling moves on the player sprite's body
the overlap
was triggered.
player.body.moves = false;
Your enterHouse
function doesn't need to accept the two sprites, and can be left as-is.
What I don't know is why this is necessary.
来源:https://stackoverflow.com/questions/36812743/new-state-with-phaser