-
Notifications
You must be signed in to change notification settings - Fork 1
Setup
There are 4 events that need to take place in order to get Animation Flags working:
- Create Event
- Step Event
- Draw Event
- Clean Up Event
Create Event:
animator = new AnimationManager("Player", spr_pixel_platformer_player);
animator.add_flag(new AnimationFlag("idle", 1, 7, 0.15));
animator.add_flag(new AnimationFlag("run", 10, 17, 0.15));
animator.set_flag("idle");Step Event:
animator.run();Draw Event:
draw_sprite(animator.sprite, animator.get_active_flag().get(), x, y);Clean Up Event:
animator.destroy();In most situations, the AnimationManager should be initiated on the object that will be responsible for running the manager and drawing the sprites.
animator = new AnimationManager("Player", spr_pixel_platformer_player);
animator.add_flag(new AnimationFlag("idle", 1, 7, 0.15));
animator.add_flag(new AnimationFlag("run", 10, 17, 0.15));
animator.set_flag("idle");animator = new AnimationManager("Player", spr_pixel_platformer_player);Create a new AnimationManager struct and assign it to the animator variable. During the creation, required parameters are being passed to it. "Player" is the name, and spr_pixel_platformer_player is the sprite.
animator.add_flag(new AnimationFlag("idle", 1, 7, 0.15));
animator.add_flag(new AnimationFlag("run", 10, 17, 0.15));Using the add_flag() method of the AnimationManager, the AnimationFlags are added to the manager.
AnimationFlag(name, start, stop, speed)
An idle and run AnimationFlag are being created and added to the AnimationManager.
animator.set_flag("idle");By default, the active_flag for AnimationManager is undefined, and must be set before use.
animator.run();Sprites are drawn using the methods of your choice. The AnimationManager will provide the sprite_index and image_index of the sprite to draw.
animator.sprite will return the sprite_index of the AnimationManager.
animator.get_active_flag().get() will return the image_index of the active flag.
draw_sprite(animator.sprite, animator.get_active_flag().get(), x, y);animator.destroy();AnimationManager will cause memory leaks if removal is not handled properly.
The flags variable for AnimationManager is a DS Map, which will persist in memory until destroyed. Running the destroy() method will destroy the flags data structure. This will cause the AnimationManager to break, so only run it once you're done with the manager.