Sprite Node
extends Sprite2D
func _ready():
# Carica texture
texture = load("res://player.png")
# Posizione
position = Vector2(400, 300)
# Scala
scale = Vector2(2, 2)
# Rotazione
rotation_degrees = 45
AnimatedSprite2D
extends AnimatedSprite2D
func _ready():
# Crea SpriteFrames
var frames = SpriteFrames.new()
# Aggiungi animazione
frames.add_animation("walk")
for i in range(4):
var texture = load("res://walk_%d.png" % i)
frames.add_frame("walk", texture)
frames.set_animation_speed("walk", 10)
sprite_frames = frames
# Play
play("walk")
func _process(delta):
if Input.is_action_pressed("ui_right"):
play("walk")
flip_h = false
elif Input.is_action_pressed("ui_left"):
play("walk")
flip_h = true
else:
stop()
Tilemap
extends TileMap
func _ready():
# Imposta tile
set_cell(0, Vector2i(0, 0), 0, Vector2i(0, 0))
# Rimuovi tile
erase_cell(0, Vector2i(1, 1))
# Ottieni tile
var tile = get_cell_source_id(0, Vector2i(0, 0))
Particles
extends GPUParticles2D
func _ready():
# Configura particelle
amount = 100
lifetime = 2.0
explosiveness = 0.8
# Process material
var material = ParticleProcessMaterial.new()
material.emission_shape = ParticleProcessMaterial.EMISSION_SHAPE_SPHERE
material.emission_sphere_radius = 50
material.initial_velocity_min = 100
material.initial_velocity_max = 200
material.gravity = Vector3(0, 98, 0)
process_material = material
# Texture
texture = load("res://particle.png")
# Emetti
emitting = true
Camera2D
extends Camera2D
func _ready():
# Segui player
enabled = true
# Smoothing
position_smoothing_enabled = true
position_smoothing_speed = 5.0
# Limiti
limit_left = 0
limit_top = 0
limit_right = 1920
limit_bottom = 1080
# Zoom
zoom = Vector2(2, 2)
func shake(intensity: float, duration: float):
var timer = 0.0
while timer < duration:
offset = Vector2(
randf_range(-intensity, intensity),
randf_range(-intensity, intensity)
)
await get_tree().create_timer(0.05).timeout
timer += 0.05
offset = Vector2.ZERO
Best Practices
- Usa
AnimatedSprite2D per animazioni
- Organizza sprite in scene riutilizzabili
- Usa
TileMap per livelli
- Camera con smoothing per movimento fluido
- Particles per effetti visivi