Menu
CoddyTech

Wrap Around the Screen

Part of the Nodes and Scenes section of Coddy's Godot journey. Lesson 17 of 28.

A node moving right keeps going past the edge of the screen. Wrapping brings it back on the other side.

An if runs its lines only when its condition is true. In _process() it is checked on every frame:

func _process(delta):
	position.y += 100 * delta
	if position.y > 360:
		position.y = 0

The node falls. When it passes the bottom of the screen, y is bigger than 360, and it jumps back to the top. The line inside the if has two tabs: one for the function, one for the if.

This game is 640 pixels wide, so the right edge is x = 640.

challenge icon

Challenge

Easy

Make the robot come back in on the left.

  1. In _process(), under the line that moves the robot, add an if for position.x more than 640.
  2. Inside it, set position.x to 0.

Press Play: the robot leaves on the right and comes back in on the left, at the same height. Then Check.

Try it yourself

extends Node2D

var speed = 200

func _process(delta):
	position.x += speed * delta

All lessons in Nodes and Scenes

Practice on your own: Godot playground