Skip to content

AnimationFlag

Brent Frymire edited this page Oct 30, 2022 · 3 revisions

AnimationFlag(name, start, stop, speed)

Constructor

Name Datatype Purpose
name string Name of AnimationFlag
start real Subimage index where the animation starts
stop real Subimage index where the animation stops
speed real Speed animation plays at, can also be negative

Constructor that marks beginning and end positions of an animation within a sprite. AnimationFlag has its own speed set individually upon creation. AnimationFlags can either calculate based on frame or by delta time. This option is set by the parent AnimationManager of the AnimationFlag.

Example:

// init animation manager using 
animator = new AnimationManager("Adventurer", spr_adventurer);
// create flag for "attack_1" animation
var _flag = new AnimationFlag("attack_1", 0, 4, 0.15);
// add flag to animation manager
animator.add_flag(_flag);

 

Methods

.get_flag_diff()

Returns: Real, difference between start and stop indexes plus 1

Name Datatype Purpose
None

Returns the difference between the stop and start indexes plus 1. Adds 1 because although subimages are base-0, the index of a subimage spans the to the next integer.

 

.get()

Returns: Real, index of flag

Name Datatype Purpose
None

Gets the index of the flag

 

.reset()

Returns: Struct, self

Name Datatype Purpose
None

Sets index to start and returns self.

 

.run()

Returns: N/A (undefined)

Name Datatype Purpose
None

Runs flag making changes using the speed to the index. This method doesn't need to be called manually, it is called by the parent, AnimationManager.run(), when it is the active_flag. If the index goes past either start or stop, depending on the sign of speed, the remainder of index will be wrapped around the indexes until it falls between them.

The flag will use delta time for its calculations if it is set by the AnimationManager in parent.

 

.__modulo__(number1, number2)

Returns: Real, remainder of a division between number1 and number2

Name Datatype Purpose
number1 real Dividend of modulo operation
number2 real Divisor of modulo operation

Returns the remainder of a division between number1 and number2. __modulo__ allows for the use of negative numbers, while modulo (mod, %) in GameMaker returns unexpected results. This function is what handles an AnimationFlag having a negative speed.

 

.toString()

Returns: String, printable representation of AnimationFlag

Name Datatype Purpose
None

Returns a printable representation of the AnimationFlag when wrapped by string().

Clone this wiki locally