What comes with each node

Node

Every node has these
  • _ready() function

    Godot runs it once, when the node first shows up in the game.

    func _ready() -> void:
    	body_entered.connect(_on_body_entered)
  • _physics_process(delta) function

    Godot runs it about 60 times a second. Movement goes here.

    func _physics_process(delta: float) -> void:
    	velocity.y += gravity * delta
  • _process(delta) function

    Godot runs it every frame. For things that are not physics, like a countdown.

    func _process(delta: float) -> void:
    	time_left -= delta
  • _unhandled_input(event) function

    Godot 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() function

    Removes the node from the game.

    queue_free()
  • add_child(node) function

    Puts a new node into the game, underneath this one.

    var bullet := bullet_scene.instantiate()
    add_child(bullet)
  • $Name function

    Grabs a child node by its name in the Scene dock.

    @onready var sprite: Sprite2D = $Sprite2D
  • is_in_group(name) function

    True if the node is in that group.

    if body.is_in_group("Player"):
    	queue_free()
  • add_to_group(name) function

    Puts the node in a group from code.

    add_to_group("creep")
  • get_tree() function

    Reaches the whole game. See the get_tree() section below.

    get_tree().reload_current_scene()

Anything you can see

Sprites, labels, buttons, bodies

Also has everything from

  • visible value

    Shown or hidden.

    game_over_panel.visible = true
  • show() / hide() function

    The same as setting visible to true or false.

    pause_menu.show()
  • modulate value

    Tints the node. The last number is see-through, from 0 to 1.

    modulate = Color(1, 1, 1, 0.45)
  • z_index value

    Draw order. Higher numbers draw on top.

    z_index = 10
  • get_global_mouse_position() function

    Where the mouse is in the game world.

    look_at(get_global_mouse_position())

Node2D

Anything placed in the 2D world

Also has everything from and

  • position value

    Where the node is, measured from its parent.

    position.x += speed * delta
  • global_position value

    Where the node is in the whole world.

    bullet.global_position = global_position
  • rotation value

    How far it is turned, in radians. rotation_degrees uses degrees.

    bullet.rotation = rotation
  • scale value

    Size. Vector2(2, 2) is twice as big.

    scale = Vector2(2, 2)
  • look_at(point) function

    Turns the node to face a point.

    look_at(get_global_mouse_position())

CharacterBody2D

Players and enemies

Also has everything from , and

  • velocity value

    How fast it is moving, and which way.

    velocity.x = direction * speed
  • move_and_slide() function

    Moves by velocity and stops at walls and floors.

    velocity = direction * speed
    move_and_slide()
  • is_on_floor() function

    True if it is standing on something.

    if Input.is_action_just_pressed("jump") and is_on_floor():
    	velocity.y = jump_velocity
  • is_on_wall() function

    True if it is touching a wall.

    if is_on_wall():
    	direction = -direction

Area2D

Coins, goals, hazards, targets

Also has everything from , and

  • body_entered signal

    Sent 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 signal

    Sent when a body leaves the area.

    body_exited.connect(_on_body_exited)
  • area_entered signal

    Sent 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 signal

    Sent when another Area2D leaves this one.

    area_exited.connect(_on_area_exited)
  • input_event signal

    Sent when the mouse does anything while pointing at the area.

    input_event.connect(_on_input_event)

CollisionShape2D

The shape a body or area touches with

Also has everything from , and

  • disabled value

    When true, the shape stops touching anything.

    $CollisionShape2D.set_deferred("disabled", true)
  • shape value

    The shape itself: a rectangle, circle or capsule.

    var box := $CollisionShape2D.shape as RectangleShape2D

Sprite2D

A picture

Also has everything from , and

  • texture value

    The picture it shows.

    sprite.texture = preload("res://art/coin.png")
  • flip_h value

    Mirrors the picture left to right.

    sprite.flip_h = velocity.x < 0
  • flip_v value

    Mirrors the picture top to bottom.

    sprite.flip_v = abs(rotation) > PI / 2
  • hframes value

    How many frames sit side by side in a sprite sheet.

    sprite.hframes = 4
  • frame value

    Which frame of the sheet to show, starting at 0.

    sprite.frame = 2

AnimationPlayer

Walk cycles and other animations

Also has everything from

  • play(name) function

    Starts an animation by name.

    anim.play("walk")
  • stop() function

    Stops the animation.

    anim.stop()
  • is_playing() function

    True while an animation is running.

    if not anim.is_playing():
    	anim.play("idle")
  • current_animation value

    The name of the animation playing now.

    if anim.current_animation != "walk":
    	anim.play("walk")
  • animation_finished signal

    Sent when an animation reaches its end.

    anim.animation_finished.connect(_on_animation_finished)

Camera2D

Following the player

Also has everything from , and

  • zoom value

    How close the camera is. Vector2(2, 2) is zoomed in.

    camera.zoom = Vector2(2, 2)
  • position_smoothing_enabled value

    When true, the camera glides after the player instead of snapping.

    camera.position_smoothing_enabled = true
  • limit_left / limit_right / limit_top / limit_bottom value

    Edges the camera will not scroll past.

    camera.limit_left = 0
    camera.limit_right = WORLD_WIDTH

RayCast2D

Looking ahead for a wall or a ledge

Also has everything from , and

  • target_position value

    Where the ray points, measured from the ray.

    ray.target_position = Vector2(0, 40)
  • is_colliding() function

    True if the ray is hitting something.

    if not ledge_check.is_colliding():
    	direction = -direction
  • get_collider() function

    The thing the ray is hitting.

    var hit := ray.get_collider()

Timer

Spawning, cooldowns, countdowns

Also has everything from

  • wait_time value

    How many seconds it counts down from.

    spawn_timer.wait_time = 1.5
  • one_shot value

    When true, it goes off once. When false, it repeats.

    shoot_timer.one_shot = true
  • start() function

    Starts counting down.

    spawn_timer.start()
  • stop() function

    Stops it early.

    spawn_timer.stop()
  • time_left value

    Seconds left before it goes off.

    timer_label.text = "Time: %.1f" % timer.time_left
  • is_stopped() function

    True if it is not counting.

    if shoot_timer.is_stopped():
    	shoot()
  • timeout signal

    Sent when it reaches zero.

    spawn_timer.timeout.connect(_on_spawn_timeout)

AudioStreamPlayer

Sound effects and music

Also has everything from

  • stream value

    The sound file it plays.

    jump_sound.stream = preload("res://sounds/jump.wav")
  • play() function

    Plays the sound from the start.

    jump_sound.play()
  • stop() function

    Stops the sound.

    music_player.stop()
  • playing value

    True while the sound is playing.

    if not music_player.playing:
    	music_player.play()
  • stream_paused value

    Pauses the sound, and keeps its place.

    music_player.stream_paused = true
  • volume_db value

    Loudness. 0 is normal, lower numbers are quieter.

    music_player.volume_db = -10.0

Label

Score, lives, messages

Also has everything from and

  • text value

    The words it shows.

    score_label.text = "Score: " + str(score)

Button

Menus

Also has everything from and

  • text value

    The words on the button.

    play_button.text = "Play again"
  • disabled value

    When true, the button cannot be clicked.

    buy_button.disabled = gold < price
  • pressed signal

    Sent when the button is clicked.

    play_button.pressed.connect(_on_play_pressed)

get_tree()

The whole game, reachable from any node
  • change_scene_to_file(path) function

    Swaps to another scene, like the next level.

    get_tree().change_scene_to_file("res://level_2.tscn")
  • reload_current_scene() function

    Starts this scene over.

    get_tree().reload_current_scene()
  • paused value

    When true, the game freezes.

    get_tree().paused = true
  • create_timer(seconds) function

    A one-time timer, with no Timer node needed.

    await get_tree().create_timer(2.0).timeout
  • current_scene value

    The scene that is running now.

    get_tree().current_scene.add_child(bullet)
  • get_nodes_in_group(name) function

    Every node in a group.

    for enemy in get_tree().get_nodes_in_group("enemies"):
    	enemy.queue_free()