_ready() functionGodot runs it once, when the node first shows up in the game.
func _ready() -> void:
body_entered.connect(_on_body_entered)_physics_process(delta) functionGodot runs it about 60 times a second. Movement goes here.
func _physics_process(delta: float) -> void:
velocity.y += gravity * delta_process(delta) functionGodot runs it every frame. For things that are not physics, like a countdown.
func _process(delta: float) -> void:
time_left -= delta_unhandled_input(event) functionGodot runs it when the player presses a key or clicks.
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("shoot"):
shoot()queue_free() functionRemoves the node from the game.
queue_free()add_child(node) functionPuts a new node into the game, underneath this one.
var bullet := bullet_scene.instantiate()
add_child(bullet)$Name functionGrabs a child node by its name in the Scene dock.
@onready var sprite: Sprite2D = $Sprite2Dis_in_group(name) functionTrue if the node is in that group.
if body.is_in_group("Player"):
queue_free()add_to_group(name) functionPuts the node in a group from code.
add_to_group("creep")get_tree() functionReaches the whole game. See the get_tree() section below.
get_tree().reload_current_scene()Also has everything from
visible valueShown or hidden.
game_over_panel.visible = trueshow() / hide() functionThe same as setting visible to true or false.
pause_menu.show()modulate valueTints the node. The last number is see-through, from 0 to 1.
modulate = Color(1, 1, 1, 0.45)z_index valueDraw order. Higher numbers draw on top.
z_index = 10get_global_mouse_position() functionWhere the mouse is in the game world.
look_at(get_global_mouse_position())Also has everything from and
position valueWhere the node is, measured from its parent.
position.x += speed * delta
global_position valueWhere the node is in the whole world.
bullet.global_position = global_position
rotation valueHow far it is turned, in radians. rotation_degrees uses degrees.
bullet.rotation = rotation
scale valueSize. Vector2(2, 2) is twice as big.
scale = Vector2(2, 2)look_at(point) functionTurns the node to face a point.
look_at(get_global_mouse_position())Also has everything from , and
velocity valueHow fast it is moving, and which way.
velocity.x = direction * speed
move_and_slide() functionMoves by velocity and stops at walls and floors.
velocity = direction * speed
move_and_slide()is_on_floor() functionTrue if it is standing on something.
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = jump_velocityis_on_wall() functionTrue if it is touching a wall.
if is_on_wall():
direction = -directionAlso has everything from , and
body_entered signalSent when a body moves into the area, like the player (a CharacterBody2D). Coins, goals and hazards use this one.
body_entered.connect(_on_body_entered)
func _on_body_entered(body: Node2D) -> void:
if body.is_in_group("Player"):
queue_free()body_exited signalSent when a body leaves the area.
body_exited.connect(_on_body_exited)area_entered signalSent when another Area2D moves into this one, like a bullet hitting a target. A body does not set this off; that is body_entered.
area_entered.connect(_on_area_entered)
func _on_area_entered(area: Area2D) -> void:
if area.is_in_group("bullets"):
queue_free()area_exited signalSent when another Area2D leaves this one.
area_exited.connect(_on_area_exited)input_event signalSent when the mouse does anything while pointing at the area.
input_event.connect(_on_input_event)Also has everything from , and
disabled valueWhen true, the shape stops touching anything.
$CollisionShape2D.set_deferred("disabled", true)shape valueThe shape itself: a rectangle, circle or capsule.
var box := $CollisionShape2D.shape as RectangleShape2DAlso has everything from , and
texture valueThe picture it shows.
sprite.texture = preload("res://art/coin.png")flip_h valueMirrors the picture left to right.
sprite.flip_h = velocity.x < 0flip_v valueMirrors the picture top to bottom.
sprite.flip_v = abs(rotation) > PI / 2hframes valueHow many frames sit side by side in a sprite sheet.
sprite.hframes = 4frame valueWhich frame of the sheet to show, starting at 0.
sprite.frame = 2Also has everything from
play(name) functionStarts an animation by name.
anim.play("walk")stop() functionStops the animation.
anim.stop()is_playing() functionTrue while an animation is running.
if not anim.is_playing():
anim.play("idle")current_animation valueThe name of the animation playing now.
if anim.current_animation != "walk":
anim.play("walk")animation_finished signalSent when an animation reaches its end.
anim.animation_finished.connect(_on_animation_finished)Also has everything from , and
zoom valueHow close the camera is. Vector2(2, 2) is zoomed in.
camera.zoom = Vector2(2, 2)position_smoothing_enabled valueWhen true, the camera glides after the player instead of snapping.
camera.position_smoothing_enabled = truelimit_left / limit_right / limit_top / limit_bottom valueEdges the camera will not scroll past.
camera.limit_left = 0
camera.limit_right = WORLD_WIDTHAlso has everything from , and
target_position valueWhere the ray points, measured from the ray.
ray.target_position = Vector2(0, 40)is_colliding() functionTrue if the ray is hitting something.
if not ledge_check.is_colliding():
direction = -directionget_collider() functionThe thing the ray is hitting.
var hit := ray.get_collider()Also has everything from
wait_time valueHow many seconds it counts down from.
spawn_timer.wait_time = 1.5one_shot valueWhen true, it goes off once. When false, it repeats.
shoot_timer.one_shot = truestart() functionStarts counting down.
spawn_timer.start()stop() functionStops it early.
spawn_timer.stop()time_left valueSeconds left before it goes off.
timer_label.text = "Time: %.1f" % timer.time_leftis_stopped() functionTrue if it is not counting.
if shoot_timer.is_stopped():
shoot()timeout signalSent when it reaches zero.
spawn_timer.timeout.connect(_on_spawn_timeout)Also has everything from
stream valueThe sound file it plays.
jump_sound.stream = preload("res://sounds/jump.wav")play() functionPlays the sound from the start.
jump_sound.play()stop() functionStops the sound.
music_player.stop()playing valueTrue while the sound is playing.
if not music_player.playing:
music_player.play()stream_paused valuePauses the sound, and keeps its place.
music_player.stream_paused = truevolume_db valueLoudness. 0 is normal, lower numbers are quieter.
music_player.volume_db = -10.0Also has everything from and
text valueThe words it shows.
score_label.text = "Score: " + str(score)change_scene_to_file(path) functionSwaps to another scene, like the next level.
get_tree().change_scene_to_file("res://level_2.tscn")reload_current_scene() functionStarts this scene over.
get_tree().reload_current_scene()paused valueWhen true, the game freezes.
get_tree().paused = truecreate_timer(seconds) functionA one-time timer, with no Timer node needed.
await get_tree().create_timer(2.0).timeoutcurrent_scene valueThe scene that is running now.
get_tree().current_scene.add_child(bullet)get_nodes_in_group(name) functionEvery node in a group.
for enemy in get_tree().get_nodes_in_group("enemies"):
enemy.queue_free()