Este video cubre los gráficos 2D en Godot 3. Comenzamos mirando las herramientas del editor 2D y luego pasamos a crear un Sprite, incluido el proceso de importación de texturas en el motor de Godot. Luego analizamos la creación de secuencias de comandos de objetos Sprite, cubriendo tareas como puntos de pivote, traducción, rotación y escalado. Luego pasamos a AtlasTextue, una sola textura con múltiples imágenes. Luego creamos un script que ilustra cómo usar una hoja de sprites, incluida la creación de un temporizador para alternar entre cuadros de animación. Finalmente, analizamos el uso del nodo AnimatedSprite, incluido el código para controlar el cambio de animaciones.
El video
Activos y muestras de código
BasicSprite.gd
extends Sprite func _ready(): #draw in the middle of the screen position = Vector2(get_viewport().size.x/2,get_viewport().size.y/2) #scale to 30% scale = Vector2(0.3,0.3) #rotate by 90degrees rotate(deg2rad(90)) set_process(false) func _process(delta): # each frame rotate by 90deg/sec rotation = self.rotation + deg2rad(90.0 * delta) # move left by 100 pixels / sec # once you go off left side of screen, jump to the right translate(Vector2(-100*delta,0)) if(position.x < 0): position = Vector2(get_viewport().size.x, get_viewport().size.y/2)
SpriteAtlas.gd
extends Sprite var timer func _ready(): timer = Timer.new() timer.connect("timeout",self,"tick") add_child(timer) timer.wait_time = 0.2 timer.start() func tick(): if self.frame < 9: self.frame = self.frame + 1 else: self.frame = 0
Sprite animado.gd
extends AnimatedSprite func _ready(): connect("animation_finished",self, "_on_AnimatedSprite_animation_finished") func _on_AnimatedSprite_animation_finished(): if self.animation == "run": animation = "jumpattack" else: animation = "run"
Los activos utilizados en este ejemplo pueden ser descargado aquí.