Brady Dowling
Brady Dowling

Reputation: 5522

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?

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.

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.

Upvotes: 1

Views: 243

Answers (1)

nazimboudeffa
nazimboudeffa

Reputation: 969

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/

Upvotes: 0

Related Questions