我正在尝试创建一个Pacman风格的门户,如果玩家进入屏幕的顶部或底部,他们将从另一侧出来,但不在另一侧。
我创建了两个栏(“门户”),并设置了一个联系方式,内容为“如果触摸此按钮,请将Y值设置为菜单栏的顶部或右侧”。但是,它陷入了无限循环,因为它只是在另一个门户的顶部(我想让它看起来像是从底部滑入)而产生并来回发送。
我考虑了对球应用数字值,以便它们仅在具有一定数字的门户网站与门户互动,该数字在生成后的0.0001秒被应用。有没有更简单的方法可以做到这一点?
func handleWallFlip() {
// When the spaceship reaches the left wall, move it to the right wall and vica versa
if spaceship.position.x < -10 {
spaceship.removeAllActions()
var movetoRightWall = SKAction.moveToX(self.frame.width, duration: 0)
spaceship.runAction(movetoRightWall)
} else if spaceship.position.x > self.frame.width + 10 {
spaceship.removeAllActions()
var movetoLeftWall = SKAction.moveToX(0, duration: 0)
spaceship.runAction(movetoLeftWall)
}
}
检查发生在-10或+10,并且放置位置为0,因此存在10个单位距离,因此不会发生无限循环
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句