Platform game infinite go

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ibo348
:warning: Old Version Published before Godot 3 was released.

Help !!
mario is going left and comes out from the right
how is it
mario

:bust_in_silhouette: Reply From: literalcitrus

The way this was achieved in Mario is quite different to how you would achieve it in Godot, as hardware and software improvements since then have changed the way we do a lot of things.

Having said that, there are two aspects to this problem: the player’s position and the player’s sprite.

The player’s position is the easy one, if the x position of the player is beyond the bounds of the level (however you have defined that), then you warp their position to the opposite side of the screen. A simple example:

if (player.get_pos().x < BOUNDS_LEFT):
    player.set_pos(Vector2(BOUNDS_RIGHT, player.get_pos().y))

The player sprite is a bit more difficult. In the example you posted, it is possible for Mario to be half on one side of the screen, and half on the other side. One of the simplest ways of achieving this is by duplicating the player sprite on the opposite side of the screen and moving it in and out based on how close to the edge the player is. The exact math depends on how you have defined your player’s position relative to their sprite, but if we assume that the player’s position is defined at the center of their sprite then the following code would work for the player being close to the left edge.

if (abs(BOUNDS_LEFT - player.get.pos().x) < sprite.get_texture().get_size().x / 2):
    duplicate_sprite.set_pos(Vector2(BOUNDS_RIGHT + abs(BOUNDS_LEFT - player.get.pos().x), player.get_pos().y))

These examples are just messy code that I don’t recommend using, but hopefully gives you an idea of how to achieve this effect.

Ok but dublicate sprite is not good not healty in the future do you have an alternate code
game is made in 1983 and successful coding :slight_smile:

ibo348 | 2017-12-22 08:07