New state with Phaser

吃可爱长大的小学妹 提交于 2019-12-25 01:19:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!