Discord
Login
Community
DARK THEME

Animated sprites starting too early

Im back hooray, but im having an issue. I want to make a game and have a dude pull out a sword. But whenever he does this he will usually start too early, any fixes

sincerely DanMan97

init = function()
  player_x = 0
  player_y = 0
  swordout = false
  time1 = 0
end

update = function()
  if keyboard.SPACE and swordout == false then
    swordout = true
    time1 = 50
  end
  if time1 > 0 then
    time1 -= 0.5
  end
end

draw = function()
  screen.clear()
  if swordout == false then
    screen.drawSprite('player',player_x,player_y,30,30)
  elsif swordout == true and time1 == 0  then
    screen.drawSprite('swordout',player_x,player_y,30,30)
  end
  if swordout == true and time1 != 0 then
    screen.drawSprite('swordpull',player_x,player_y,30,30)
  end
end

Here is the project https://microstudio.io/DanMan97/dnd2/46M9RCSK/ WASD control, Space jumps, and E pull sword out

The animations are always "playing" in the background, and drawing them will draw their current frame. Set the frame of the sprite resource to 0 each time the animation is changed.

Thank you, I fixed it up. 👍

Post a reply

Progress

Status

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