A library for self-contained, time-aware action functions in your Gamemaker instances.
See the example project, or the read below for more information on how to use it.
- Self-contained, time-aware action loops for instances - create modular behaviours or animations easily.
- Useful helper methods like
at()
,between()
,before()
,after()
,steps()
andevery()
to handle many use cases. - Simple and fluent interface.
- Out-of-the-box "fire and forget" handling - Actions run once, and won't run again while playing.
- Straightforward scope handling - the instance that creates the Action is
self
, or you can rebind it with thebind()
method.
- Arguments for
play()
/execute()
. - Hooks for advanced behaviour;
onStopped()
,onPlayed
,onPaused
, etc.
As the name would suggest, this Library sets out to create a simple way to have your instances perform repeatable, time-aware actions.
Each action is a constructor that wraps a time source, and contains a number of helpful functions to track and modify its behaviour.
As an example, let's say you want your instance to flash red a few times whenever it's damaged:
actionDamaged = new Action( function( a ) {
var flashTime = 5;
image_blend = c_white;
// Every 10 frames, flash red for 5 frames, but only if we haven't been running for more than 60 frames
if ( a.every( 10, 5 ) && a.before( 60 ) ) {
image_blend = c_red;
}
// Just after we stop flashing, reset our image_blend and stop the action
if ( a.at( 70 ) ) {
image_blend = c_white;
a.stop();
}
} );
actionDamaged.play();
Note that the function you pass to the action is scoped to the instance creating it - we're accessing the Action itself through our function's first argument.
Check out the repo's example project for more like this.
Actions starts with the Action()
constructor.
You can access the struct within your action function with its first argument (in this example, we've called it a
).
myAction = new Action( function( a ) ) {
// do stuff
}
Description: Executes the Action, starting the time source.
Returns: {Struct.Action}
Description: Rebinds the method passed to the Action - by default, it's bound to the instance creating the Action.
Returns: {Struct.Action}
Description: Executes the Action, starting the time source - an alias for execute()
.
Returns: {Struct.Action}
Resets the action's timer.
Returns: {Struct.Action}
Pauses the action.
Returns: {Struct.Action}
Stops the action, resetting its timer.
Returns: {Struct.Action}
Prevents the action from playing again - this does NOT stop a playing action.
Returns: {Struct.Action}
Allows the action to play again if it was locked.
Returns: {Struct.Action}
Returns true if the action's timer is at 0.
Returns: {bool}
Returns true if the action's timer is at t.
Returns: {bool}
Returns true every t frames, for duration frames.
Returns: {bool}
Returns true if the action's timer is equal to any of the arguments.
Note: this will be renamed to "atTimes( args... )" in the next version.
Returns: {bool}
Returns true if the action's timer is before t.
Returns: {bool}
Returns true if the action's timer is between s and e.
Returns: {bool}
Returns true if the action's timer is after t.
Returns: {bool}
Returns true if the action is playing, or false if it's paused or stopped.
Returns: {bool}
Returns true if the action is paused, or false if it's playing or hasn't run yet.
Returns: {bool}
Returns true if the action is stopped, or hasn't run yet.
Returns: {bool}
Returns true if the action has a time source attached (it has run at least once).
Returns: {bool}
Returns the number of times this action has been played.
Returns: {real}