Skip to content
Brent Frymire edited this page Mar 2, 2022 · 8 revisions

Overview

There are 4 events that need to take place in order to get Animation Flags working:

  1. Create Event
  2. Step Event
  3. Draw Event
  4. 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();

1. Create Event

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");

Create manager

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.

Add flags

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.

Set active flag

animator.set_flag("idle");

By default, the active_flag for AnimationManager is undefined, and must be set before use.

2. Step Event

animator.run();

3. Draw Event

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);

4. Clean Up Event

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.

Clone this wiki locally