Type Method

javaScriptActionWithScript:duration:

Creates an action that executes a JavaScript script periodically over a specified duration.

Declaration

+ (SCNAction *)javaScriptActionWithScript:(NSString *)script duration:(NSTimeInterval)seconds;

Parameters

script

A string containing JavaScript source code.

seconds

The duration of the action, in seconds.

Return Value

A new action object.

Discussion

SceneKit exposes its classes, methods, and functions in the JavaScript context that runs the script—see the SCNJavaScript.h header file for details.

When the action executes, SceneKit runs the script repeatedly until the action’s duration expires. Each time SceneKit runs the script, it computes the elapsed time since the action began executing (as a fraction of the action’s duration between 0.0 and 1.0) and makes it available to the script as a variable named elapsedTime. The script can also reference the SCNNode object running the action as a variable named node.

This action is not reversible; the reverse action executes the same script.

See Also

Creating Custom Actions

+ runBlock:

Creates an action that executes a block.

+ runBlock:queue:

Creates an action that executes a block on a specific dispatch queue.

+ customActionWithDuration:actionBlock:

Creates an action that executes a block periodically over a specified duration.