New state with Phaser

2019-09-10 15:33发布

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条回答
贪生不怕死
2楼-- · 2019-09-10 16:10

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.

查看更多
登录 后发表回答