简体   繁体   English

如何在Phaser3中的静态地图上循环/重新启动精灵运动

[英]How to loop/restart sprite movement on a static map in Phaser3

I'm working on a Super Mario War type of game and want players to be able to run through the right side of the screen and end up on the left side. 我正在开发《超级马里奥战争》类型的游戏,希望玩家能够穿越屏幕右侧并最终到达左侧。 Something like what you see below with the yellow Mario: 类似于您在下面看到的黄色马里奥车:

Ideally it would work like this where the character can be perfectly split from one side to the other. 理想情况下,它将像这样从角色的一侧到另一侧完全分开。 Have you seen a precedent like this or is there a built-in way to do this with Phaser3? 您是否看到过这样的先例,或者是否有使用Phaser3的内置方法?

Two thoughts I've had so far. 到目前为止,我有两个想法。 I could just check if the player is off screen on the right then manually change the x position to the left but this wouldn't have the nice split you see above so there would need to be some "blind spot" where the player isn't seen at all. 我可以检查播放器是否在右侧屏幕外,然后手动将x位置更改为左侧,但这不会像您在上面看到的那样好,因此需要在播放器所在的位置有一些“盲点”。根本看不到。

The other thing I could do is duplicate one player if they're going outside the screen on one side but this seems a little too complex and would probably cause issues with edge cases. 我可以做的另一件事是,如果一个玩家要从一侧移出屏幕,则复制一个玩家,但这似乎有点太复杂了,可能会导致边缘情况的问题。

Note : Here is how they did it in the original game but I don't think this will give me the split effect in Phaser: flipsidesifneeded . 注意 :这是他们在原始游戏中的做法,但是我认为这不会给我带来Phaser中的分割效果: flipsidesifneeded

You can try the same test as in the original game by trying just something like this 您可以通过尝试类似这样的方式来尝试与原始游戏相同的测试

if (player.x < 0){
    player.x = 640
} else if (player.x > 640){
    player.x = 0
}

More in this jsfiddle https://jsfiddle.net/nazimboudeffa/L7pqd5h6/ 此jsfiddle中的更多内容https://jsfiddle.net/nazimboudeffa/L7pqd5h6/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM