Skip to content

Engine.CustomLoop.API

Jesper Sørensen edited this page Sep 7, 2014 · 1 revision

Class: CustomLoop

Engine. CustomLoop

A loop class. Contains a list of functions to run each time the loop executes. For the loop to be executed, it will have to be added to the current room via the Engine.currentRoom.addLoop. A loop also has it's own time that is stopped whenever the loop is not executed. This makes it possible to schedule a function execution that will be "postponed" if the loop gets paused.

new CustomLoop(framesPerExecution, maskFunction)

Parameters:
Name Type Argument Default Description
framesPerExecution number <optional>
1

The number of frames between each execution of the custom loop

maskFunction function <optional>
function(){}

A function that will be run before each execution, if the function returns true the execution proceeds as planned, if not, the execution will not be run

Properties:
Name Type Description
framesPerExecution number

The number of frames between each execution of the custom loop

maskFunction function

A function that will be run before each execution, if the function returns true the execution proceeds as planned, if not, the execution will not be run

time number

The "local" time of the loop. The loop's time is stopped when the loop is not executed.

execTime number

The time it took to perform the last execution

Source:

Methods

<private> addAnimation(animation)

Adds a new animation to the animator class (done automatically when running the animate-function).

Parameters:
Name Type Description
animation object

An animation object

Source:

<private> addExecutionsQueue()

Adds the current executions queue to the list of planned executions. Automatically called at the end of each frame

Source:

<private> addFunctionsQueue()

Queues a function for being added to the executed functions. The queue works as a buffer which prevent functions, that have just been added, from being executed before the next frame.

Source:

attachFunction(caller, func)

Attaches a function to the loop.

Parameters:
Name Type Description
caller Object

The object to run the function as

func function

The function to run on each execution of the custom loop

Source:

detachFunction(caller, func) → {boolean}

Detaches a function from the loop. If the same function is attached multiple times (which is never a good idea), only the first occurrence is detached.

Parameters:
Name Type Description
caller Object

The object the function was run as

func function

The function to detach from the loop

Source:
Returns:

Whether or not the function was found and detached

Type
boolean

detachFunctionsByCaller(caller) → {function[]}

Detaches all attached functions with a specific caller

Parameters:
Name Type Description
caller Object

The object the function was run as

Source:
Returns:

An array of detached functions

Type
function[]

detachFunctionsByFunction(func) → {function[]}

Detaches all occurrences of a specific function, no matter the caller.

Parameters:
Name Type Description
func function

The function to detach from the loop

Source:
Returns:

An array of detached functions

Type
function[]

execute()

Executes the custom loop. This will execute all the functions that have been added to the loop, and checks all scheduled executions to see if they should fire. This function will automatically be executed, if the loop has been added to the current room, or the engine's masterRoom

Source:

removeAnimationsOfObject(object)

Stop all animations of a specific object from the loop

Parameters:
Name Type Description
object Mixin.Animatable

The object to stop all animations of

Source:

schedule(caller, func, delay)

Schedules a function to be run after a given amount of time in the loop. If the loop is paused before the execution has happened, the loop's time will stand still, and therefore the scheduled execution will not happen until the loop is started again.

Parameters:
Name Type Description
caller Object

The object with which to run the function (by default the custom loop itself)

func function

The function to execute

delay number

The delay in ms

Source:

unschedule(func, caller) → {boolean}

Unschedules a single scheduled execution. If multiple similar executions exists, only the first will be unscheduled.

Parameters:
Name Type Description
func function

The function to unschedule an execution of

caller Object

The object with which the function was to be executed (by default the custom loop itself)

Source:
Returns:

Whether or not the function was found and unscheduled

Type
boolean

unscheduleAll() → {function[]}

Unschedules all scheduled executions

Source:
Returns:

An array of all the unscheduled functions

Type
function[]

unscheduleByCaller(caller) → {boolean|Array.<function()>}

Unschedule all executions scheduled with a specific caller

Parameters:
Name Type Description
caller object

The caller

Source:
Returns:

False if no functions has been unscheduled, otherwise an array containing the unscheduled functions

Type
boolean | Array.<function()>

unscheduleByFunction(func) → {boolean|Array.<function()>}

Unschedule all scheduled executions of a specific function, no matter the caller.

Parameters:
Name Type Description
func function

The function to unschedule all executions of

Source:
Returns:

False if no functions has been unscheduled, otherwise an array containing the unscheduled functions

Type
boolean | Array.<function()>

<private> updateAnimations()

Update the loop's animations in a single loop (called by updateAllLoops)

Source:

Generated with wicked.
Clone this wiki locally