Discord
Login
Community
DARK THEME

Restarting an animation

When drawing a sprite, is there any way to restart the animation associated with said sprite? For example, a hurt animation playing start to end every time the player is injured.

Does it not work if you just put collision and if collide then show animation and I think that should work

The easiest and most common way to do this is to create two sprites, one of the injured animation, and the other of the player. When the player is injured switch to the injured sprite which has the animation then when the animation finishes switch back to the player.

example:

player = object()
       sprite = "Uninjured"

       GotHit = function()
         return // don't feel like putting anything here but you get the point
       end
      // rest of your code here
    end
     
    uninjured = function()
       player.sprite = "Uninjured"
    end
     
    injured = function()
       player.sprite = "Injured"
    end

    if player.GotHit() then
       injured()
         else
       uninjured()
    end

    draw = function()
       screen.drawSprite(player.sprite,*information*,*information*,*information*,*information*)
    end

Now, I am by no means an 'expert' at this so take this with a grain of salt but I have used this method in the past and it is pretty reliable.

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community