Menu
CoddyTech

Wrap Around the Screen

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

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

The robot moves right and leaves the screen. Make it wrap: when it passes x = 640, put it back at x = 0, on the left, at the same height.

Try it yourself

extends Node2D

var speed = 200

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

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Nodes and Scenes

Practice on your own: Godot playground