This video covers 2D graphics in Godot 3. We start by looking at the 2D editor tools then move on to create a Sprite, including covering the process of importing textures into the Godot engine. We then look at scripting Sprite objects, covering tasks like pivot points, translating, rotating and scaling. We then move on to AtlasTextue, a single texture with multiple images. We then create a script illustrating how to use a sprite sheet, including creating a timer to flip between animation frames. Finally we look at using the AnimatedSprite node, including code to control switching animations.
Assets and Code Samples
#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
# 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
if(position.x < 0):
position = Vector2(get_viewport().size.x, get_viewport().size.y/2)
timer = Timer.new()
timer.wait_time = 0.2
if self.frame < 9:
self.frame = self.frame + 1
self.frame = 0
if self.animation == "run":
animation = "jumpattack"
animation = "run"
The assets used in this example can be downloaded here.