June 2018
Beginner to intermediate
298 pages
7h 38m
English
Another feature of classic 2D arcade games is screen wrap. If the player goes off one side of the screen, they appear on the other side. In practice, you teleport or instantaneously change the ship's position to the opposite side. Add the following to the class variables at the top of the script:
var screensize = Vector2()
And add this to _ready():
screensize = get_viewport().get_visible_rect().size
Later, the game's main script will handle setting screensize for all of the game's objects, but for now, this will allow you to test the screen wrapping with just the player scene.
When first approaching this problem, you might think you could use the body's position property and, if it exceeds the bounds of the screen, set it to ...
Read now
Unlock full access