Action Basics

Creating Actions

The first step in animating your object's properties, is to create an action. To create one, call the desired action creation function and store the resulting action in a variable. For example:

var moveAction = PRActionCreateMoveTo(300, 200, PRActionEaseLinear, 3)

The above command will create an action that, when played by an object, will move that object from its current x/y position on the screen to the new position (300, 200). It will take 3 seconds for that animation to fully play out and it will use the PRActionEaseLinear easing function to do it. For a list of all of the available easing functions you can use, please refer to the cPRActionEasingFunctions script asset.

Container actions are special in that they can contain other actions to be played in sequence, in parallel or repetitively. Actions constructed in this way are called compound actions.

Action Creation Functions

There are many action creation functions available to you included in this extension. In fact, there are 4 script assets filled with functions that create actions. The script assets are:

cPRActionStandardActions

Contains all of the basic time-tracked actions that you can use individually or as parts of a larger sequence.

cPRActionInstantActions

Contains several "one-shot" actions that perform a specific function immediately.

cPRActionContainerActions

Container actions that group actions together to play them simultaneously, in sequence or repeating.

cPRActionCompoundActions

Contains pre-built ready-to-use common actions.

cPRActionStandardActions Contains all of the basic time-tracked actions that you can use individually or as parts of a larger sequence. Documentation
cPRActionInstantActions Contains several "one-shot" actions that perform a specific function immediately. Documentation
cPRActionContainerActions Container actions that group actions together to play them simultaneously, in sequence or repeating. Documentation
cPRActionCompoundActions Contains pre-built ready-to-use common actions. Documentation

Playing Actions

Actions on their own don't do anything. In order for the action to run, you must instruct a PRAction-derived object to play the action. You do this by calling the object method PRPlayAction(). For example:

PRPlayAction(moveAction)

The above command will instruct the current object to play the action contained in the moveAction variable. That action will continue to play, from beginning to end, automatically until the animation is done. There is nothing else you need to do.

Note that calling PRPlayAction to play an action will not stop any of the object's currently playing actions. This means that you can play any number of actions simultaneously. For example:

PRPlayAction(moveAction)  // Object is now moving.
PRPlayAction(flashAction// Object is now flashing AND moving.

You can provide a name when instructing an object to play an action. For example:

PRPlayAction(moveAction, "Move")

In the above example, the name "Move" is attached to the object's running action, not to the action itself. This is so that you can refer to that particular running action by name for other PRAction methods that require it, such as the PRStopAction() method. Also note that PRPlayAction returns a slot number, which is another way to uniquely identify the running action. Example:

var moveSlot = PRPlayAction(moveAction)

When an action has completed running, the running action will be terminated and can no longer be referenced by its name or slot number as it is no longer among that object's list of running actions. Note that the action itself remains untouched throughout this process and can be reused at will for the same object or another.

If you'd like to know whether or not a specific action is playing, you can use the PRIsActionPlaying() method to find that out. Example:

var isPlaying = PRIsActionPlaying("Move")

The above method call will return true if the running action named "Move" is currently playing, otherwise it will return false. You can instead provide the PRIsActionPlaying() method a slot number instead of a name for the parameter.

If you have the name of a running action and you'd like to know what the slot number is, you can find out by calling the PRGetSlotForActionWithName() method and providing it with the name of the running action. Example:

var slotNum = PRGetSlotForActionWithName("Move")

The above call will return a slot number for the first running action found with the name "Move". If no running action with that name is found, the method will return noone.

For a count of the number of running actions assigned to an object, call the PRGetActionsCount() method. This will return the total number of running actions, even if the current object's PRAction system is paused. Example:

var actionCount = PRGetActionsCount()

Note that actions are reusable. So playing an action does not invalidate it in any way. The action can be kept and played again as needed.

Stopping Actions

Running actions will stop on their own when they have completed their course. However, you can stop any running action at any time so long as you know the running action's name or slot number. To do this, you use the PRStopAction() method which accepts either an action name or a slot number as a parameter. Example:

PRStopAction("Move")   // Stops the running action named "Move".
PRStopAction(moveSlot// Stops the running action at slot number moveSlot.

The above commands will stop the current object's running actions identified by the name "Move" and the slot number in the moveSlot variable. The running action will be removed from the current object's list of running actions and can no longer be referenced.

It is also possible to stop ALL of an object's running actions using the PRStopAllActions() method, as in the following example:

PRStopAllActions() // Stop all of the current object's running actions.

All of an object's actions can also be temporarily paused using the PRPauseActions() method, as in the follwing example:

PRPauseActions() // Pauses the object's PRAction play system.

In the above example, all of the current object's actions will be paused, including any new actions the object is instructed to play after this command. Essentially, that object's PRAction system as a whole is on pause. You can resume the object's PRAction system by using the PRResumeActions() method. Example:

PRResumeActions() // Resumes the object's PRAction play system.

To know what the current playing status of an object is, use the PRGetActionStatus() method. This method will return one of the following 3 constants:

PRACTION_STATUS_PLAYING Will return this if the current object is playing one or more actions.
PRACTION_STATUS_STOPPED Will return this if the current object isn't playing any actions.
PRACTION_STATUS_PAUSED Will return this if the current object PRAction system has been paused.

© 2021 Prismatic Realms, Inc. Contact

Green Hosting Badge