Constructors

SceneObject

Constructor Summary

SceneObject

A Scene Object is an entity that can be added to the scene in WADE. It may contain sprites and may have behaviors associated with it.

Fields Summary

Functions Summary

SceneObject.addBehavior (behaviorClass)

Add a behavior to the scene object
SceneObject.addSprite (sprite, offset, index)

Add a sprite to the scene object
SceneObject.clone (positionX, positionY)

Clone the scene object
SceneObject.drawToImage (imageName, replace)

Draw a SceneObject to an image in CPU memory.
SceneObject.fadeIn (time, callback)

Fade in effect, gradually changing the opacity (alpha) of the all the sprites of this object from 0 to 1. If any sprite is invisible, it is set to visible before fading in.
SceneObject.fadeOut (time, callback)

Fade out effect, gradually changing the opacity (alpha) of the all the sprites of this object from 1 to 0. After fading out, all sprites are set to invisible.
SceneObject.getAlignment ()

Get the screen alignment of a scene object. This determines where the object is positioned following a resize event
SceneObject.getAngularVelocity ()

Get the current angular velocity of the object
SceneObject.getBehavior (name)

Get a behavior of the scene object
SceneObject.getBehaviorByIndex (index)

Get a behavior of the scene object, give its index in the array of behaviors
SceneObject.getBehaviors ()

Get an array containing all the behaviors of this object
SceneObject.getBoundingBox ()

Get the axis-aligned bounding box that contains all the sprites of this SceneObject
SceneObject.getFlowChart ()

Get a reference to the current flow chart data structure associated with this SceneObject. This will be null unless it was set via setFlowChart, or via the SceneObject constructor.
SceneObject.getFunctionsScript ()

Get the script (as a string) that defines the functions associated with this object when it was constructed or the last time importFunctions was called
SceneObject.getGrid ()

Get a copy of the grid properties of the SceneObject
SceneObject.getGridRef ()

Get a reference to the grid properties of the SceneObject
SceneObject.getMovementSpeed ()

Get the scene object's movement speed
SceneObject.getName ()

Get the current name of this object, if it was set when the object was created or with SceneObject.setName()
SceneObject.getOverlappingObjects (searchAllLayers, precision)

Get an array of objects overlapping this object
SceneObject.getPath ()

Get the currently active Path for this SceneObject
SceneObject.getPosition ()

Get the world space position of the scene object
SceneObject.getRotation ()

Get the current rotation angle of the scene object
SceneObject.getScreenBoundingBox ()

Get the axis-aligned bounding box that contains all the sprites of this SceneObject in screen space
SceneObject.getSprite (index)

Get the sprite object corresponding to a given sprite index
SceneObject.getSpriteAtPosition (screenPosition)

Get a sprite of the scene object at a given screen position (if there is one).
SceneObject.getSpriteByName (name)

Get a sprite object given its name
SceneObject.getSpriteCount ()

Get the number of sprites in the scene object
SceneObject.getSpriteIndex (sprite)

Get the current index of a sprite
SceneObject.getSpriteOffset (indexOrName)

Get the position of a sprite relative to the position of its parent scene object
SceneObject.getTargetPosition ()

Get the position where the scene object is moving to
SceneObject.getTargetRotation ()

Get the rotation angle the scene object is rotating to. Note that if there is no target rotation angle, this will simply return the current rotation angle of the object.
SceneObject.getVelocity ()

Get the current linear velocity of the object
SceneObject.importFunctions (functionObject)

Import functions from an object that contains their string representations
SceneObject.interval (time, functionName, data, variance)

Schedule the execution and processing of a function for this object, repeating it periodically. The scheduled function will be cancelled when the object is removed from the scene, or when SceneObject.unschedule is called
SceneObject.isAnimating ()

Check whether any sprite in the scene object is playing any animation
SceneObject.isInScene ()

Check whether the scene object is in the scene
SceneObject.isListeningFor (eventName)

Check if the object is currently listening for a specific type of event. This is the same as calling wade.isEventListener(SceneObject, eventName)
SceneObject.isMoving ()

Check whether the scene object is currently moving
SceneObject.isOnScreen ()

Check whether the SceneObject is currently visible on the screen
SceneObject.isTemplate ()

Check whether this object is a template. A template is a scene object that never receives any events, and is set to be invisible as soon as it's added to the scene
SceneObject.isVisible (checkAllSprites)

Check if a scene object is visible. This returns true if at least one of the child sprites is visible, unless you set checkAllSprites to true, in which case this function only returns true if all sprites are visible.
SceneObject.listenFor (eventName)

Start listening for an event. This is the same as calling wade.addEventListener(SceneObject, eventName)
SceneObject.moveTo (posX, posY, speed)

Move a scene object to the specified world space position, with a given speed
SceneObject.overlapsObject (object, precision)

Check whether this scene object overlaps another scene object
SceneObject.overlapsSprite (sprite, precision)

Check whether this scene object overlaps a sprite
SceneObject.playAnimation (name, direction)

Play an animation on all the sprites of the scene object that have an animation with a matching name
SceneObject.process (functionName, data)

Execute a function of this object and its behaviors. If the scene object or any of its behaviors have member functions matching the functionName parameter, those functions will be called and will be passed the data parameter
SceneObject.processEvent (eventName, eventData)

Process an event for the scene object and all its behaviors. If the scene object or any of its behaviors have member functions matching the eventName parameter, those functions will be called, passing the eventData parameter
SceneObject.removeAllSprites ()

Remove all the sprites from the scene object.
SceneObject.removeBehavior (name)

Remove a behavior from a scene object
SceneObject.removeBehaviorByIndex (index)

Remove a behavior from a scene object, using the behavior index
SceneObject.removeSprite (sprite)

Remove a sprite from the scene object
SceneObject.removeSpriteByIndex (index)

Remove a sprite from the scene object, given a sprite index
SceneObject.resumeAnimation ()

Resume playing any animations that had been stopped
SceneObject.rotateTo (angle, angularVelocity)

Gradually rotate an object towards a target angle
SceneObject.schedule (time, functionName, data)

Schedule the execution and processing of a function for this object. The scheduled function will be cancelled when the object is removed from the scene, or when SceneObject.unschedule is called
SceneObject.serialize (stringify, propertiesToExclude, serializeFunctions)

Export this SceneObject to an object that can then be used to create a new SceneObject like this one (by passing the resulting object to the SceneObject constructor).
SceneObject.setAlignment (leftRight, topBottom)

Set the screen alignment of a scene object. This determines where the object is positioned following a resize event
SceneObject.setAngularVelocity (velocity)

Set the angular velocity of the object.
SceneObject.setAsTemplate (toggle)

Set a scene object to be a template. A template is a scene object that never receives any events, and is set to be invisible as soon as it's added to the scene. By default, scene objects are note templates.
SceneObject.setFlowChart (flowChartData)

Assigns a flow chart to this SceneObject. If the object is already in the scene, the flow chart is executed immediately. If the object is not in the scene, the flow chart is executed the next time (and every time) the object is added to the scene.
SceneObject.setGrid (gridData)

Change the grid properties of the SceneObject
SceneObject.setName (name)

Set a name for the scene object, so it can be retrieved via wade.getSceneObject(). Note that you can't have more objects with the same name in the scene at the same time.
SceneObject.setPath (path, setInitialValues, speedMultiplier)

Set the currently active Path for this SceneObject. The SceneObject will start following the path immediately.
SceneObject.setPosition (positionX, positionY)

Set the world space position of the scene object. The position of all its sprites will be updated accordingly.
SceneObject.setRotation (rotation)

Set a rotation angle for the scene object
SceneObject.setSpriteOffset (indexOrName, offset)

Set the position of a sprite relative to the position of the scene object
SceneObject.setSpriteOffsets (spriteOffsets)

Set the world space position offsets for the sprites of the scene object (i.e. the sprite positions relative to the scene object's position)
SceneObject.setVelocity (velocityX, velocityY)

Set the current linear velocity of the object. Note that calling this function on an object that is moving towards a specific target (that had been set with a call to moveTo) will cancel the current movement towards the target.
SceneObject.setVisible (toggle)

Show or hide a scene object
SceneObject.step ()

Perform a simulation step for the scene object.
SceneObject.stopAnimation ()

Stop any animations that are currently playing
SceneObject.stopListeningFor (eventName)

Stop listening for an event. This is the same as calling wade.removeEventListener(SceneObject, eventName)
SceneObject.stopMoving ()

Stop a scene object that is currently moving. An 'onMoveComplete' event will be triggered.
SceneObject.toGrid (numColumns, numRows, marginX, marginY)

Create a grid of clones of this SceneObject. This SceneObject becomes the top-left element of the grid
SceneObject.unschedule (eventName)

Cancel any scheduled events with the given name for this object

Constructor Details

SceneObject

A Scene Object is an entity that can be added to the scene in WADE. It may contain sprites and may have behaviors associated with it.

Sprite|Array|object sprites (optional): A sprite object, or an array of sprites. You can also use this constructor by passing in a single object (so just the first parameter) that contains all the SceneObject properties that you want to set (see remarks below for more details).


Function|Array behaviors (optional): A behavior function, or an array of behavior functions


number posX (optional, defaults to 0): The X coordinate of the initial world space position


number posY (optional, defaults to 0): The Y coordinate of the initial world space position


string name (optional): The name of the scene object (so you can obtain a reference to this object via wade.getSceneObject)



Remarks:
You can also use this constructor by passing in a single object (so just the first parameter) that contains all the SceneObject properties that you want to set. In this case, the object structure is as follows (all fields are optional):

{
type: 'SceneObject',
position: {x: number, y: number},
rotation: number,
behaviors: Array,
sprites: Array,
spriteOffsets: Array,
alignment: {x: string, y: string},
name: string,
visible: boolean,
isTemplate: boolean,
path: string,
grid: {type: string, gridMap: Array, collisionMap: Array},
addToScene: {autoListen: boolean, params: {}},
flowChart: {},
functions: {},
properties: {}
}

Where properties is a set of properties to copy into the new scene object. Note that properties are deep-copied, and cannot contain functions or cyclical references.

The sprites array can contain any number of sprites. See the Sprite documentation for more details about the format used to describe each sprite.

The path parameter can be used to specify the name of a Path that the object should follow when it's added to the scene. Note that the path must already be in the scene when the SceneObject is created.
The grid parameter is used to restrict movement, positioning and collisions to the isometric or tilemap terrain.
The flowChart object may contain flow chart data as described in the documentation for wade.runFlowChart(). This flow chart would then be executed every time the object is added to the scene.
The addToScene object can be used if you want the object to be added to the scene immediately. In this case, you can specify which set of parameters should be passed to the onAddToScene event (params), and whether you want the object to automatically listen for handled input events (autoListen).

The functions object can contain any number of strings that will be interpreted as member functions of the SceneObject.
^

Fields Details

Function Details

SceneObject.addBehavior (behaviorClass)

Add a behavior to the scene object

behaviorClass : The definition of a behavior function. Note that this is not the same as an instance of a behavior function.


Returns Object : The instance of the behavior function that was just added to the object.

^
SceneObject.addSprite (sprite, offset, index)

Add a sprite to the scene object

Sprite sprite : The sprite to add


object offset (optional): An object with 'x' and 'y' fields representing the position offset and an 'angle' field representing the angular offset. If omitted or falsy, the offset will be (0, 0, 0). If any of the fields is omitted, its value will be 0.


number index (optional): Where to add the sprite. If omitted, the sprite will be added after any sprites already present in this scene object. If 'index' is greater than the number of sprites currently present in the scene object, the sprite will be added at the end. Check the returned value to determine the actual index that was used.


Returns number : The index of the sprite that was just added

^
SceneObject.clone (positionX, positionY)

Clone the scene object

number positionX (optional): The new X coordinate for the clone's position. If omitted the X coordinate of the original object is used


number positionY (optional): The new Y coordinate for the clone's position. If omitted the Y coordinate of the original object is used


Returns object : A copy of the scene object. Note that the new object won't be automatically added to the scene, even if the object you are cloning was in the scene.

^
SceneObject.drawToImage (imageName, replace)

Draw a SceneObject to an image in CPU memory.

string imageName : The target image name


boolean replace (optional): Whether to replace any existing image with that name. Set this to false to draw on top of an existing image.

^
SceneObject.fadeIn (time, callback)

Fade in effect, gradually changing the opacity (alpha) of the all the sprites of this object from 0 to 1. If any sprite is invisible, it is set to visible before fading in.

number time : How many seconds the transition should last. Note that this won't be extremely accurate - to make the effect smooth, it must ultimately depend on the actual frame rate of the app.


function callback (optional): A function to execute when the transition is over

^
SceneObject.fadeOut (time, callback)

Fade out effect, gradually changing the opacity (alpha) of the all the sprites of this object from 1 to 0. After fading out, all sprites are set to invisible.

number time : How many seconds the transition should last. Note that this won't be extremely accurate - to make the effect smooth, it must ultimately depend on the actual frame rate of the app.


function callback (optional): A function to execute when the transition is over

^
SceneObject.getAlignment ()

Get the screen alignment of a scene object. This determines where the object is positioned following a resize event

Returns Object : An object whose 'x' and 'y' fields represent the alignment of the scene object. If the alignment is set, valid values are 'left' and 'right' for the 'x' field, and 'top' and 'bottom' for the 'y' field

^
SceneObject.getAngularVelocity ()

Get the current angular velocity of the object

Returns number : The angular velocity of the object, in radians per second

^
SceneObject.getBehavior (name)

Get a behavior of the scene object

string name (optional): The name of the behavior to get.


Returns Object : The requested behavior. If the 'name' parameter is omitted or falsy, the first behavior that was registered with the scene object.

^
SceneObject.getBehaviorByIndex (index)

Get a behavior of the scene object, give its index in the array of behaviors

number index (optional): The index of the sprite to retrieve


Returns Object : The requested behavior. Note that this is an instance of the behavior, not the behavior class that was passed to the SceneObject's constructor.

^
SceneObject.getBehaviors ()

Get an array containing all the behaviors of this object

Returns Array : An array containing all the behaviors of this object.

^
SceneObject.getBoundingBox ()

Get the axis-aligned bounding box that contains all the sprites of this SceneObject

Returns object : An object with minX, minY, maxY and maxY properties describing the bounding box in world space. If the scene object has no sprites, an object where all properties are set to 0 is returned.

^
SceneObject.getFlowChart ()

Get a reference to the current flow chart data structure associated with this SceneObject. This will be null unless it was set via setFlowChart, or via the SceneObject constructor.

Returns Object : The flow chart data. See the documentation of wade.runFlowChart() for details.

^
SceneObject.getFunctionsScript ()

Get the script (as a string) that defines the functions associated with this object when it was constructed or the last time importFunctions was called

Returns string : The source of the functions script

^
SceneObject.getGrid ()

Get a copy of the grid properties of the SceneObject

Returns Object : The grid properties of the SceneObject

^
SceneObject.getGridRef ()

Get a reference to the grid properties of the SceneObject

Returns Object : The grid properties of the SceneObject

^
SceneObject.getMovementSpeed ()

Get the scene object's movement speed

Returns number : The current movement speed

^
SceneObject.getName ()

Get the current name of this object, if it was set when the object was created or with SceneObject.setName()

Returns string : The name of this object

^
SceneObject.getOverlappingObjects (searchAllLayers, precision)

Get an array of objects overlapping this object

boolean searchAllLayers (optional): Whether to extend the search to all layers. This is false by default, meaning that only overlapping sprites on the same layer will be considered.


string precision (optional): How accurately to search for overlaps. This can be either 'axis-aligned' (which would consider the axis-aligned bounding box of the sprites), or 'oriented', which takes into account the rotation of each sprite. Default is 'axis-aligned'.


Returns SceneObjectGroup : A SceneObjectGroup containing all the objects that are overlapping this object

^
SceneObject.getPath ()

Get the currently active Path for this SceneObject

Returns Path : The currently active path.

^
SceneObject.getPosition ()

Get the world space position of the scene object

Returns Object : An object with 'x' and 'y' field representing world space coordinates

^
SceneObject.getRotation ()

Get the current rotation angle of the scene object

Returns number : The current rotation angle in radians. A positive value indicates a clockwise rotation

^
SceneObject.getScreenBoundingBox ()

Get the axis-aligned bounding box that contains all the sprites of this SceneObject in screen space

Returns object : An object with minX, minY, maxY and maxY properties describing the bounding box in screen space. If the scene object has no sprites, an object where all properties are set to 0 is returned.

^
SceneObject.getSprite (index)

Get the sprite object corresponding to a given sprite index

number|string index (optional): The sprite index or the sprite name. If omitted or falsy, the first sprite is returned.


Returns Sprite|undefined : The sprite object

^
SceneObject.getSpriteAtPosition (screenPosition)

Get a sprite of the scene object at a given screen position (if there is one).

Note that at most one sprite will be returned. If more sprites are present at the same screen position, the one at the front will be returned.


Object screenPosition : A position object, with 'x' and 'y' coordinates


Returns Object : An object with the following fields:

isPresent - A boolean that describes whether any sprite was found

topLayer - The id of the top layer where a sprite was found

spriteIndex - The index of the sprite that was found. You can use this to get the sprite object with a call to getSprite
^
SceneObject.getSpriteByName (name)

Get a sprite object given its name

string name : The name of the sprite


Returns Sprite : The sprite object corresponding to the given name

^
SceneObject.getSpriteCount ()

Get the number of sprites in the scene object

Returns number : The number of sprites

^
SceneObject.getSpriteIndex (sprite)

Get the current index of a sprite

Sprite sprite : The sprite to look for


Returns number : The index of the sprite

^
SceneObject.getSpriteOffset (indexOrName)

Get the position of a sprite relative to the position of its parent scene object

number indexOrName (optional): The sprite index or a string representing the sprite name. If omitted or falsy, the first sprite offset is returned.


Returns Object : An object with 'x' and 'y' fields representing the position offset and an 'angle' field representing the angular offset

^
SceneObject.getTargetPosition ()

Get the position where the scene object is moving to

Returns Object : An object with 'x' and 'y' fields representing a world space position, or null if no target position is set

^
SceneObject.getTargetRotation ()

Get the rotation angle the scene object is rotating to. Note that if there is no target rotation angle, this will simply return the current rotation angle of the object.

Returns number : The target rotation angle

^
SceneObject.getVelocity ()

Get the current linear velocity of the object

Returns {x: number, y: number} : An object with x and y fields representing the linear velocity of the object

^
SceneObject.importFunctions (functionObject)

Import functions from an object that contains their string representations

Object functionObject : An object in the format {functionName1: functionCode1, functionName2: functionCode2, ...} where functionCode is always a string.

^
SceneObject.interval (time, functionName, data, variance)

Schedule the execution and processing of a function for this object, repeating it periodically. The scheduled function will be cancelled when the object is removed from the scene, or when SceneObject.unschedule is called

number time : How many milliseconds to wait between function calls


string functionName : The name of the function to execute for this object. If the object or any of its behaviors have a function with this name, it will be executed


object data (optional): The data to pass to the event function


number variance (optional): A maximum amount of milliseconds to randomly add or subtract to the time parameter

^
SceneObject.isAnimating ()

Check whether any sprite in the scene object is playing any animation

Returns Boolean : Whether any sprite in the scene object is playing any animation

^
SceneObject.isInScene ()

Check whether the scene object is in the scene

Returns boolean : Whether the scene object is in the scene

^
SceneObject.isListeningFor (eventName)

Check if the object is currently listening for a specific type of event. This is the same as calling wade.isEventListener(SceneObject, eventName)

string eventName : The name of the event


Returns boolean : Whether the object is currently listening for the event

^
SceneObject.isMoving ()

Check whether the scene object is currently moving

Returns boolean : Whether the scene object is currently moving

^
SceneObject.isOnScreen ()

Check whether the SceneObject is currently visible on the screen

Returns boolean : Whether the SceneObject is currently visible on the screen

^
SceneObject.isTemplate ()

Check whether this object is a template. A template is a scene object that never receives any events, and is set to be invisible as soon as it's added to the scene

Returns boolean : whether this object is a template

^
SceneObject.isVisible (checkAllSprites)

Check if a scene object is visible. This returns true if at least one of the child sprites is visible, unless you set checkAllSprites to true, in which case this function only returns true if all sprites are visible.

boolean checkAllSprites (optional, defaults to false): Whether to check all sprites


Returns boolean : Whether the SceneObject is currently visible

^
SceneObject.listenFor (eventName)

Start listening for an event. This is the same as calling wade.addEventListener(SceneObject, eventName)

string eventName : The name of the event

^
SceneObject.moveTo (posX, posY, speed)

Move a scene object to the specified world space position, with a given speed

number posX : The X coordinate of the target position


number posY : The Y coordinate of the target position


number speed : The movement speed, in world space units per second

^
SceneObject.overlapsObject (object, precision)

Check whether this scene object overlaps another scene object

SceneObject object : The other scene object to test


string precision (optional): How accurate the test should be. This could be 'axis-aligned' (the default value when this parameter is omitted), which only considers the axis-aligned bounding boxes of both Sprites; 'oriented' which takes into account the rotations of both Sprites; or 'pixel' that does a (much slower) per-pixel test, discarding transparent pixels.


Returns boolean : Whether the two scene objects overlap each other

^
SceneObject.overlapsSprite (sprite, precision)

Check whether this scene object overlaps a sprite

Sprite sprite : The sprite to test


string precision (optional): How accurate the test should be. This could be 'axis-aligned' (the default value when this parameter is omitted), which only considers the axis-aligned bounding boxes of both Sprites; 'oriented' which takes into account the rotations of both Sprites; or 'pixel' that does a (much slower) per-pixel test, discarding transparent pixels.*


Returns boolean : Whether the scene object and the sprite overlap each other

^
SceneObject.playAnimation (name, direction)

Play an animation on all the sprites of the scene object that have an animation with a matching name

string name : The animation name


string direction (optional): The direction of the animation. It can be 'forward', 'reverse' or 'ping-pong' (which means forward and then reverse). Default is 'forward'

^
SceneObject.process (functionName, data)

Execute a function of this object and its behaviors. If the scene object or any of its behaviors have member functions matching the functionName parameter, those functions will be called and will be passed the data parameter

string functionName : The name of the function(s) to execute


data (optional): The data to pass to the functions. This can be any type and is optional.


Returns boolean : Whether any of the functions called returned a truthy value.

^
SceneObject.processEvent (eventName, eventData)

Process an event for the scene object and all its behaviors. If the scene object or any of its behaviors have member functions matching the eventName parameter, those functions will be called, passing the eventData parameter

string eventName : The name of the event to process


Object eventData (optional): The data to pass to the functions that will be called


Returns Boolean : Whether any of the functions called return a truthy value.

^
SceneObject.removeAllSprites ()

Remove all the sprites from the scene object.
^
SceneObject.removeBehavior (name)

Remove a behavior from a scene object

string name : The name of the behavior to remove


Returns boolean : Whether any behavior with the specified name was found and removed

^
SceneObject.removeBehaviorByIndex (index)

Remove a behavior from a scene object, using the behavior index

number index : The index of the behavior to remove

^
SceneObject.removeSprite (sprite)

Remove a sprite from the scene object

Sprite sprite : The sprite to remove

^
SceneObject.removeSpriteByIndex (index)

Remove a sprite from the scene object, given a sprite index

number index : The sprite to remove

^
SceneObject.resumeAnimation ()

Resume playing any animations that had been stopped
^
SceneObject.rotateTo (angle, angularVelocity)

Gradually rotate an object towards a target angle

number angle : The target angle (in radians)


number angularVelocity : The angular velocity (in radians per second)

^
SceneObject.schedule (time, functionName, data)

Schedule the execution and processing of a function for this object. The scheduled function will be cancelled when the object is removed from the scene, or when SceneObject.unschedule is called

number time : How many milliseconds to wait before firing the event


string functionName : The name of the function to execute for this object. If the object or any of its behaviors have a function with this name, it will be executed


object data (optional): The data to pass to the event function

^
SceneObject.serialize (stringify, propertiesToExclude, serializeFunctions)

Export this SceneObject to an object that can then be used to create a new SceneObject like this one (by passing the resulting object to the SceneObject constructor).

boolean stringify (optional): Whether the resulting object should be serialized to JSON. If this is set to true, this function returns a string representation of the scene object.


Array propertiesToExclude (optional): An array of strings that contains the name of the properties of this SceneObject that you do NOT want to export.


boolean serializeFunctions (optional): Whether to serialize functions (such as onMouseDown, etc). False by default


Returns object|string : An object that represents the current scene object

^
SceneObject.setAlignment (leftRight, topBottom)

Set the screen alignment of a scene object. This determines where the object is positioned following a resize event

string leftRight (optional): If this is 'left' or 'right', the distance between the object and one edge of the screen will be kept constant after a resize event


string topBottom (optional): If this is 'top' or 'bottom', the distance between the object and one edge of the screen will be kept constant after a resize event

^
SceneObject.setAngularVelocity (velocity)

Set the angular velocity of the object.

number velocity : The angular velocity of the object, in radians per second

^
SceneObject.setAsTemplate (toggle)

Set a scene object to be a template. A template is a scene object that never receives any events, and is set to be invisible as soon as it's added to the scene. By default, scene objects are note templates.

boolean toggle (optional): Whether this scene object should be a template or not. If omitted, this parameter is assumed to be true.

^
SceneObject.setFlowChart (flowChartData)

Assigns a flow chart to this SceneObject. If the object is already in the scene, the flow chart is executed immediately. If the object is not in the scene, the flow chart is executed the next time (and every time) the object is added to the scene.
In any case, the flow chart is cancelled when the object is removed from the scene. This means that any node in the chart that is supposed to be executed when the object is not in the scene will not be executed. However the active node (even those that include asynchrnous operations) will always be fully executed.

object flowChartData : A data structure describing the flow chart. See the documentation of wade.runFlowChart() for details.

^
SceneObject.setGrid (gridData)

Change the grid properties of the SceneObject

{type: string, collisionMap: Array, gridMap: Array, gridCoords: Object} gridData : The grid properties of the object.

^
SceneObject.setName (name)

Set a name for the scene object, so it can be retrieved via wade.getSceneObject(). Note that you can't have more objects with the same name in the scene at the same time.

string name (optional): The name to set

^
SceneObject.setPath (path, setInitialValues, speedMultiplier)

Set the currently active Path for this SceneObject. The SceneObject will start following the path immediately.

Path|string path : A Path object, or the name of a path that is currently in the scene.


boolean setInitialValues (optional): Whether the object and its sprite should be scanned to set the initial values of all properties that are used on Node 0 (the first node) of the path. Note that this effectively creates a copy of the path, it doesn't modify the original one.


number speedMultiplier (optional, defaults to 1): A factor to multiply the base speed defined in the path data

^
SceneObject.setPosition (positionX, positionY)

Set the world space position of the scene object. The position of all its sprites will be updated accordingly.

number|Object positionX : A coordinate for the horizontal axis, or an object with 'x' and 'y' fields representing world space coordinates


number positionY (optional): A coordinate for the vertical axis

^
SceneObject.setRotation (rotation)

Set a rotation angle for the scene object

number rotation : The rotation angle in radians. A positive value indicates a clockwise rotation

^
SceneObject.setSpriteOffset (indexOrName, offset)

Set the position of a sprite relative to the position of the scene object

number indexOrName : The sprite index or the name of the sprite


Object offset (optional): An object with optional 'x' and 'y' fields representing the sprite offset and an 'angle' field representing the angular offset

^
SceneObject.setSpriteOffsets (spriteOffsets)

Set the world space position offsets for the sprites of the scene object (i.e. the sprite positions relative to the scene object's position)

Object spriteOffsets : An object, or an array of objects, with optional 'x' and 'y' fields representing the position offsets and an 'angle' field representing the angular offsets

^
SceneObject.setVelocity (velocityX, velocityY)

Set the current linear velocity of the object. Note that calling this function on an object that is moving towards a specific target (that had been set with a call to moveTo) will cancel the current movement towards the target.

number|{x: number, y: number} velocityX : The x component of the velocity (a number), or an object with x and y fields representing the linear velocity of the object


number velocityY : The y component of the velocity

^
SceneObject.setVisible (toggle)

Show or hide a scene object

boolean toggle : Whether to show the scene object

^
SceneObject.step ()

Perform a simulation step for the scene object.

This function is called automatically by WADE, that aims to maintain a constant calling rate where possible (60Hz by default).
^
SceneObject.stopAnimation ()

Stop any animations that are currently playing
^
SceneObject.stopListeningFor (eventName)

Stop listening for an event. This is the same as calling wade.removeEventListener(SceneObject, eventName)

string eventName : The name of the event

^
SceneObject.stopMoving ()

Stop a scene object that is currently moving. An 'onMoveComplete' event will be triggered.
^
SceneObject.toGrid (numColumns, numRows, marginX, marginY)

Create a grid of clones of this SceneObject. This SceneObject becomes the top-left element of the grid

number numColumns : The number of columns in the grid


number numRows : The number of rows in the grid


number marginX (optional): The horizontal spacing between columns (in world units). This is 0 by default


number marginY (optional): The vertical spacing between rows (in world units). This is 0 by default


Returns Array : A bi-dimensional array containing all grid elements. The element at column X and row Y can be accessed via returnValue[x][y]. Column and row indices start at 0

^
SceneObject.unschedule (eventName)

Cancel any scheduled events with the given name for this object

string eventName : The name of the scheduled event to cancel

^

Events

onAddToScene

This function gets passed a data object
When calling wade.addSceneObject(), the 3rd argument is the data object that gets passed to this function. You can define this object in the editor, in a SceneObject's Properties tab where it says Add To Scene Parameters. This is an optional parameter, so data may be null or undefined
onAnimationEnd

This function gets passed a data object
data.name string The name of the animation
onAnimationStart

This function gets passed a data object
data.name string The name of the animation
data.restarting boolean Whether this is the same animation as the previously active one
onAppTimer

This event fires at fixed intervals
By default this happens once every second, but can be changed with wade.setAppTimerInterval
onBlur

This event fires when the app loses focus
For example when it goes to a background tab or, in a mobile application, when there is a phone call or another event that takes priority
onCameraMove

This function gets passed a data object
data.oldPosition object with x, y and z properties
data.newPosition object with x, y and z properties
onCameraMoveComplete

This function gets passed a data object
data.cameraPosition object with x, y and z properties
onClick

This function gets passed a data object
data.screenPosition object with x and y properties describing the position, in pixels, relative to the center of the game area
data.position object with x and y properties describing the position, in world units, relative to the center of the object
data.button number Which button was pressed. This is 0 for left mouse or finger touch, 1 for middle mouse, 2 for right mouse
data.spriteIndex number The index of the sprite that received the event
Note that a click event is defined as a mouseDown followed by a mouseUp that is roughly on the same position. This behavior can be adjusted using wade.setClickTolerance
onMouseDown

This function gets passed a data object
data.screenPosition object with x and y properties describing the position, in pixels, relative to the center of the game area
data.position object with x and y properties describing the position, in world units, relative to the center of the object
data.button number Which button was pressed. This is 0 for left mouse or finger touch, 1 for middle mouse, 2 for right mouse
data.shift boolean Whether the shift key was pressed
data.ctrl boolean Whether the ctrl key was pressed
data.alt boolean Whether the alt key was pressed
data.meta boolean Whether the meta key was pressed
data.pointerId number A number to identify which pointer (finger) the event refers to in a multi-touch scenario
data.spriteIndex number The index of the sprite that received the event
onMouseUp

This function gets passed a data object
data.screenPosition object with x and y properties describing the position, in pixels, relative to the center of the game area
data.position object with x and y properties describing the position, in world units, relative to the center of the object
data.button number Which button was pressed. This is 0 for left mouse or finger touch, 1 for middle mouse, 2 for right mouse
data.shift boolean Whether the shift key was pressed
data.ctrl boolean Whether the ctrl key was pressed
data.alt boolean Whether the alt key was pressed
data.meta boolean Whether the meta key was pressed
data.pointerId number A number to identify which pointer (finger) the event refers to in a multi-touch scenario
data.spriteIndex number The index of the sprite that received the event
onMouseMove

This function gets passed a data object
data.screenPosition object with x and y properties describing the position, in pixels, relative to the center of the game area
data.position object with x and y properties describing the position, in world units, relative to the center of the object
data.shift boolean Whether the shift key was pressed
data.ctrl boolean Whether the ctrl key was pressed
data.alt boolean Whether the alt key was pressed
data.meta boolean Whether the meta key was pressed
data.pointerId number A number to identify which pointer (finger) the event refers to in a multi-touch scenario
data.spriteIndex number The index of the sprite that received the event
Note that this is also triggered by touch events
onMouseWheel

This function gets passed a data object
data.screenPosition object with x and y properties describing the position, in pixels, relative to the center of the game area
data.position object with x and y properties describing the position, in world units, relative to the center of the object
data.shift boolean Whether the shift key was pressed
data.ctrl boolean Whether the ctrl key was pressed
data.alt boolean Whether the alt key was pressed
data.meta boolean Whether the meta key was pressed
data.value number The amount of movement of the mouse wheel
data.spriteIndex number The index of the sprite that received the event
Note that this is also triggered by a pinch-to-zoom gesture on touch devices
onMouseIn

This function gets passed a data object
data.screenPosition object with x and y properties describing the position, in pixels, relative to the center of the game area
data.position object with x and y properties describing the position, in world units, relative to the center of the object
data.pointerId number A number to identify which pointer (finger) the event refers to in a multi-touch scenario
data.spriteIndex number The index of the sprite that received the event
Note that this is also triggered by touch events
onMouseOut

This function gets passed a data object
data.screenPosition object with x and y properties describing the position, in pixels, relative to the center of the game area
data.position object with x and y properties describing the position, in world units, relative to the center of the object
data.pointerId number A number to identify which pointer (finger) the event refers to in a multi-touch scenario
data.spriteIndex number The index of the sprite that received the event
Note that this is also triggered by touch events
onSwipeLeft

This function gets passed a data object
data.screenPosition object with x and y properties describing the position, in pixels, relative to the center of the game area
data.position object with x and y properties describing the position, in world units, relative to the center of the object
data.spriteIndex number The index of the sprite that received the event
Note that this can be triggered by both mouse and touch events
onSwipeRight

This function gets passed a data object
data.screenPosition object with x and y properties describing the position, in pixels, relative to the center of the game area
data.position object with x and y properties describing the position, in world units, relative to the center of the object
data.spriteIndex number The index of the sprite that received the event
Note that this can be triggered by both mouse and touch events
onSwipeUp

This function gets passed a data object
data.screenPosition object with x and y properties describing the position, in pixels, relative to the center of the game area
data.position object with x and y properties describing the position, in world units, relative to the center of the object
data.spriteIndex number The index of the sprite that received the event
Note that this can be triggered by both mouse and touch events
onSwipeDown

This function gets passed a data object
data.screenPosition object with x and y properties describing the position, in pixels, relative to the center of the game area
data.position object with x and y properties describing the position, in world units, relative to the center of the object
data.spriteIndex number The index of the sprite that received the event
Note that this can be triggered by both mouse and touch events
onCollision

This function gets passed a data object
data.otherObject SceneObject The SceneObject we are colliding with
data.fixtures object with A and B fields pointing to the fixtures involved in the collision (one for object A, one for object B)
data.bodyIndex string This can be either 'A' or 'B' depending on whether this is object A or object B
data.manifold object with localNormal and localPoint (both wade.vec2 vectors) and a type string that can be 'circles', 'faceA', or 'faceB' describing the what local space localNormal and localPoint refer to
data._b2dData object The raw underlying box2d data for the collision event
You can return true from this function to cancel the collision resolution
Note that this event is only available for objects that have the PhysicsObject behavior, and won't be triggered unless you enable wade.physics
onContainerResize

This function gets passed a data object
This event is triggered when the container div with all the canvas elements gets resized (by default this is a DOM element whose id is 'wade_container_div')
data.width The new width of the div
data.height The new width of the div
onFocus

This event fires when the app regains focus
For example when the app's tab is selected after being in the background or, in a mobile application, after an interrupting event such as a phone call is complete
onGamepadButtonDown

This function gets passed a data object
data.gamepadIndex number The index of the gamepad in the array of currently enabled gamepads
data.gamepadId string A unique identifier for the gamepad
data.button number An identifier for the current button
onGamepadButtonUp

This function gets passed a data object
data.gamepadIndex number The index of the gamepad in the array of currently enabled gamepads
data.gamepadId string A unique identifier for the gamepad
data.button number An identifier for the current button
onGamepadConnected

This function gets passed a data object
data.gamepadId string A unique identifier for the gamepad
Note that a gamepad is not considered to be connected until a button is pressed while the app is active
onGamepadDisconnected

This function gets passed a data object
data.gamepadId string A unique identifier for the gamepad
onUpdate

This function runs once per step
No arguments are passed into this function
onRemoveFromScene

No arguments are passed into this function
This function is called every time the object is removed from the scene
onMoveComplete

No arguments are passed into this function
This function is called when an object reaches its destination after a call to SceneObject.moveTo()
onResize

This function gets passed a data object
This function is called when the size of the game area changes
data.width number The new width of the game area, in pixels
data.height number The new height of the game area, in pixels
onRotationComplete

No arguments are passed into this function
This function is called when an object reaches its target orientation after a call to SceneObject.rotateTo()
onPathEnd

This function gets passed a data object
data.path Path The current path
onPathNode

This function gets passed a data object
data.path Path The current path
data.nodeIndex number The index of the node that has just been reached
onOverlap

This function gets passed a data object
data.otherObject SceneObject The object that is overlapping this object
onKeyUp

This function gets passed a data object
data.keyCode number The key code
data.keyName string The name of the key
data.shift boolean Whether the shift key was pressed
data.ctrl boolean Whether the ctrl key was pressed
data.alt boolean Whether the alt key was pressed
data.meta boolean Whether the meta key was pressed
onKeyDown

This function gets passed a data object
data.keyCode number The key code
data.keyName string The name of the key
data.shift boolean Whether the shift key was pressed
data.ctrl boolean Whether the ctrl key was pressed
data.alt boolean Whether the alt key was pressed
data.meta boolean Whether the meta key was pressed
onKeyPress

This function gets passed a data object
data.charCode number The ASCII code corresponding to the key that was pressed
data.charName string A string representing the key that was pressed