How to change Sprite texture to Animation

前端 未结 1 1651
傲寒
傲寒 2021-01-27 18:25

I have a Sprite that spawns every second, what I wan\'t to do is change the sprite texture to animation, and the when it\'s touched it will be back to a normal texture.

相关标签:
1条回答
  • 2021-01-27 18:54

    To change from a texture to an animation

    Create a subclas of Sprite called MySprite or something, and override the draw(batch) method.

    In the overriden draw method, if you want to draw a texture, simply call super.draw(batch), otehrwise use your animation draw code. You can get the delta time using Gdx.graphics.getDeltaTime()

    Why you have to specify timePassed

    Your program will run at different frame rates to the animation, so by telling the animation how much time has passed, it can work out what frame it should be on according to it's own framerate.

    Note that the framerate of your app can vary from frame-to-frame depending on how much work it has to do.

    0 讨论(0)
提交回复
热议问题