Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon Join the GFS Discord Server!

Godot 3 Tutorial–2D Graphics, Sprites And Animation


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.


The Video

Assets and Code Samples

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
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
  if(position.x < 0):
    position = Vector2(get_viewport().size.x, get_viewport().size.y/2)

extends Sprite

var timer

func _ready():
  timer =
  timer.wait_time = 0.2

func tick():
    if self.frame < 9:
      self.frame = self.frame + 1
      self.frame = 0

extends AnimatedSprite

func _ready():
  connect("animation_finished",self, "_on_AnimatedSprite_animation_finished")

func _on_AnimatedSprite_animation_finished():
  if self.animation == "run":
    animation = "jumpattack"
    animation = "run"


The assets used in this example can be downloaded here.


Back to Tutorial Series Homepage

blog comments powered by Disqus

AppGameKit Studio

See More Tutorials on!

Month List