Discord
Login
Community
DARK THEME

Help to change framerate of sprite.

[Solved] I'm wanting to change the framerate of an animation based on a game speed variable. Is there a sprite method or other way to access/change a sprite/animation frame rate?

Yes, there is. You have to create an object pointing to the sprite in question and then you have access to its properties.
See quick example here:
https://microstudio.dev/i/TinkerSmith/spriteanimspeed/

// simple example that shows how to change the animation speed
// of a sprite

init = function()
 playerSprite = sprites["player"]   // point to the sprite
 speed = playerSprite.fps           // read the initial FPS
end

update = function()
  speed += (keyboard.press.UP-keyboard.press.DOWN)   // add -1,0,+1
  playerSprite.fps = speed          // assign new FPS
end

draw = function()
  screen.clear()
  screen.drawText("FPS : "+speed,0,35,12)
  screen.drawText("[UP] [DOWN] to change FPS",0,-35,10)  
  screen.drawSprite(playerSprite,0,0,40)
end

Thanks for your detailed reply. Helped me out perfectly!

Post a reply

Progress

Status

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