本文介绍了移相器的新状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过碰撞切换状态.因此,当玩家击中另一个精灵时,应该切换状态,但不会.

I'm trying to switch state with a collision. So when the player hits another sprite it should switch state, but it doesn't..

首先,我要声明播放器和create:下的enterDoor精灵:

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);

然后我要在update:下进行重叠:

Then I'm trying to make the overlap under update: :

this.game.physics.arcade.overlap(player, playerDoor, this.enterHouse, null, this);

enterHouse是另一个功能:

And enterHouse is another function:

enterHouse: function() {
  this.state.start('Menu');  
}

我在做什么错?

推荐答案

因此,使用上面的代码,我根本无法使overlap触发.在播放器精灵的 moves 上禁用后body overlap被触发.

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;

您的enterHouse函数不需要接受两个精灵,可以保持原样.

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.

这篇关于移相器的新状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 23:41