pygamelib.gfx.core.Animation¶
-
class
pygamelib.gfx.core.
Animation
(display_time=0.05, auto_replay=True, frames=None, animated_object=None, refresh_screen=None, initial_index=None, parent=None)¶ The Animation class is used to give the ability to have more than one model for a BoardItem. A BoardItem can have an animation and all of them that are available to the Game object can be animated through Game.animate_items(lvl_number). To benefit from that, BoardItem.animation must be set explicitely. An animation is controlled via the same state system than the Actuators.
The frames are all stored in a list called frames, that you can access through Animation.frames.
Parameters: - display_time (float) – The time each frame is displayed
- auto_replay (bool) – controls the auto replay of the animation, if false once the animation is played it stays on the last frame of the animation.
- frames (array[str|Sprixel|Sprite]) – an array of “frames” (string, sprixel or sprite)
- animated_object (
BoardItem
) – The object to animate. This parameter is deprecated. Please use parent instead. It is only kept for backward compatibility. The parent parameter always takes precedence over this one. - parent (
BoardItem
) – The parent object. It is also the object to animate. Important: We cannot animate anything else that BoardItems and subclasses. - refresh_screen (function) – The callback function that controls the redrawing of the screen. This function reference should come from the main game.
Example
def redraw_screen(game_object): game_object.clear_screen() game_object.display_board() item = BoardItem(model=Sprite.ALIEN, name='Friendly Alien') # By default BoardItem does not have any animation, we have to # explicitely create one item.animation = Animation(display_time=0.1, parent=item, refresh_screen=redraw_screen)
-
__init__
(display_time=0.05, auto_replay=True, frames=None, animated_object=None, refresh_screen=None, initial_index=None, parent=None)¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
([display_time, auto_replay, …])Initialize self. add_frame
(frame)Add a frame to the animation. current_frame
()Return the current frame. next_frame
()Update the parent’s model, sprixel or sprite with the next frame of the animation. pause
()Set the animation state to PAUSED. play_all
()Play the entire animation once. remove_frame
(index)Remove a frame from the animation. reset
()Reset the Animation to the first frame. search_frame
(frame)Search a frame in the animation. start
()Set the animation state to constants.RUNNING. stop
()Set the animation state to STOPPED.