- FBX files don’t work well, so it is recommended to use GLB instead.
Tiled Map Editor:
Submit Browser Games:
Physics Engine:
Godot Shaders:
Rotate 2D Sprite
extends Sprite2D
var speed = 400
var angular_speed = PI
func _init():
print("hello world!")
func _process(delta):
rotation += angular_speed * delta
var velocity = Vector2.UP.rotated(rotation) * speed
position += velocity * delta
Rotate with arrow keys
extends Sprite2D
var speed = 400
var angular_speed = PI
func _process(delta):
var direction = 0
if Input.is_action_pressed("ui_left"):
direction = -1
if Input.is_action_pressed("ui_right"):
direction = 1
rotation += angular_speed * direction * delta
var velocity = Vector2.ZERO
if Input.is_action_pressed("ui_up"):
velocity = Vector2.UP.rotated(rotation) * speed
if Input.is_action_pressed("ui_down"):
velocity = Vector2.UP.rotated(rotation) * (-1) * speed
position += velocity * delta
- delta is the amount of time that the previous frame took to complete. Using this value ensures that your movement will remain consistent even if the frame rate changes.
- delta is 0.0133 (for 75Hz)
- No spaces in filenames, nor special characters!
Signal (Event) Example
extends Sprite2D
var speed = 400
var angular_speed = PI
func _process(delta):
rotation += angular_speed * delta
var velocity = Vector2.UP.rotated(rotation) * speed
position += velocity * delta
func _on_button_pressed():
set_process(not is_processing())
Timer Example
extends Sprite2D
var speed = 400
var angular_speed = PI
func _process(delta):
rotation += angular_speed * delta
var velocity = Vector2.UP.rotated(rotation) * speed
position += velocity * delta
func _on_button_pressed():
set_process(not is_processing())
func _ready():
var timer = get_node("Timer")
timer.timeout.connect(_on_timer_timeout)
func _on_timer_timeout():
visible = not visible
Custom Signal Example
extends Node2D
signal health_changed(old_value, new_value)
var health = 10
func take_damage(amount):
var old_health = health
health -= amount
health_changed.emit(old_health, health)
PackedScene Instance
extends Node2D
var laser_scene: PackedScene = preload("res://scenes/laser.tscn")
func _on_gate_player_entered_gate(body):
print("player has entered gate")
print(body)
func _on_player_laser():
var laser = laser_scene.instantiate()
#add_child(laser)
$Projectiles.add_child(laser)
func _on_player_grenade():
var granade = granade_scene.instantiate() as RigidBody2D