Skip to content
Download

Animate a sprite

The base speed is the sprite fps, set in the sprite editor. In code, animSpeed multiplies that value.

objects/Explosion.lua
function onSpawn(self)
self.animSpeed = 2
end
function onAnimationEnd(self)
self:destroy()
end
self.animSpeed = 0
self.frame = 1
self.sprite = self.hspeed ~= 0 and "player_andando" or "player_parado"
self.flipX = true
self.angle = 45
  • animSpeed = 0 stops the animation; frame picks the frame, starting at 0.
  • Changing sprite returns the animation to frame 0.
  • With no fps on the sprite, animSpeed counts in frames per step: 0.25 = 15 frames per second.
  • angle rotates only the drawing; flipX mirrors the drawing and the collision.

Reference: Objects and events.