Animation#
This is a simple animation tool, allowing individual frame files to be composed into a sprite animation, like so:
import ppb
from ppb.features.animation import Animation
class MySprite(ppb.Sprite):
image = Animation("sprite_{1..10}.png", 4)
Multi-frame files, like GIF or APNG, are not supported.
Pausing#
Animations support being paused and unpaused. In addition, there is a “pause
level”, where multiple calls to pause()
cause the animation to become
“more paused”. This is useful for eg, pausing on both scene pause and effect.
import ppb
from ppb.features.animation import Animation
class MySprite(ppb.Sprite):
image = Animation("sprite_{1..10}.png", 4)
def on_scene_paused(self, event, signal):
self.image.pause()
def on_scene_continued(self, event, signal):
self.image.unpause()
def set_status(self, frozen):
if frozen:
self.image.pause()
else:
self.image.unpause()
Reference#
- class ppb.features.animation.Animation(filename, frames_per_second)[source]#
An “image” that actually rotates through numbered files at the specified rate.
- Parameters:
filename (str) – A path containing a
{2..4}
indicating the frame numberframes_per_second (number) – The number of frames to show each second
- __init__(filename, frames_per_second)[source]#
- Parameters:
filename (str) – A path containing a
{2..4}
indicating the frame numberframes_per_second (number) – The number of frames to show each second
- copy()[source]#
Create a new Animation with the same filename and framerate. Pause status and starting time are reset.
- property current_frame#
Compute the number of the current frame (0-indexed)