RuntimeObject

RuntimeObject

RuntimeObject represents an object being used on a RuntimeScene.

A gdjs.RuntimeObject should not be instantiated directly, always a child class (because gdjs.RuntimeObject don't call onCreated at the end of its constructor).

Constructor

new RuntimeObject(runtimeScene, objectData)

Parameters:
Name Type Description
runtimeScene

The scene the object belongs to..

objectData

The initial properties of the object.

Source:

Members

getSqDistanceTo

Get the squared distance, in pixels, from the object center to a position.

Deprecated:
  • Use `getSqDistanceToPosition` instead.

Source:

persistentUuid

An optional UUID associated to the object to be used for hot reload. Don't modify or use otherwise.

Source:

pick

A property to be used by external algorithms to indicate if the object is picked or not in an object selection. By construction, this is not "thread safe" or "re-entrant algorithm" safe.

Source:

Methods

(static) collisionTest(obj1, obj2, ignoreTouchingEdges)

Return true if the hitboxes of two objects are overlapping

Parameters:
Name Type Description
obj1

The first runtimeObject

obj2

The second runtimeObject

ignoreTouchingEdges

If true, then edges that are touching each other, without the hitbox polygons actually overlapping, won't be considered in collision.

Returns:
Type Description

true if obj1 and obj2 are in collision

Source:

(static) distanceTest()

Check the distance between two objects.

Source:

(static) getNameIdentifier()

Get the identifier associated to an object name. Some features may want to compare objects name a large number of time. In this case, it may be more efficient to compare objects name identifiers.

Source:

(static) getVariableChildCount(variable)

Get the number of children from a variable

Parameters:
Name Type Description
variable

The variable to be accessed

Returns:
Type Description

The number of children

Source:

(static) getVariableNumber(variable)

Get the value of a variable considered as a number. Equivalent of variable.getAsNumber()

Parameters:
Name Type Description
variable

The variable to be accessed

Returns:
Type Description

The value of the specified variable

Source:

(static) getVariableString(variable)

Get the value of a variable considered as a string. Equivalent of variable.getAsString()

Parameters:
Name Type Description
variable

The variable to be accessed

Returns:
Type Description

The string of the specified variable

Source:

(static) returnVariable(variable)

Return the variable passed as argument without any change. Only for usage by events.

Parameters:
Name Type Description
variable

The variable to be accessed

Returns:
Type Description

The specified variable

Source:

(static) setVariableNumber(variable, newValue)

Shortcut to set the value of a variable considered as a number

Parameters:
Name Type Description
variable

The variable to be changed

newValue

The value to be set

Source:

(static) setVariableString(variable, newValue)

Shortcut to set the value of a variable considered as a string

Parameters:
Name Type Description
variable

The variable to be changed

newValue String

The value to be set

Source:

(static) variableChildExists(variable, childName)

Parameters:
Name Type Description
variable

The variable to be tested

childName

The name of the child

Source:

(static) variableClearChildren(variable)

Parameters:
Name Type Description
variable

The variable to be cleared

Source:

(static) variableRemoveChild(variable, childName)

Parameters:
Name Type Description
variable

The variable to be changed

childName

The name of the child

Source:

activateBehavior(name, enable)

De/activate a behavior of the object.

Parameters:
Name Type Description
name String

The behavior name.

enable boolean

true to activate the behavior

Source:

addEffect(effectData)

Add a new effect, or replace the one with the same name.

Parameters:
Name Type Description
effectData

The data describing the effect to add.

Source:

addForce(x, y, multiplier)

Add a force to the object to move it.

Parameters:
Name Type Description
x

The x coordinates of the force

y

The y coordinates of the force

multiplier

Set the force multiplier

Source:

addForceTowardObject(object, len, multiplier)

Add a force oriented toward another object.
(Shortcut for addForceTowardPosition)

Parameters:
Name Type Description
object

The target object

len

The force length, in pixels.

multiplier

Set the force multiplier

Source:

addForceTowardPosition(x, y, len, multiplier)

Add a force oriented toward a position

Parameters:
Name Type Description
x

The target x position

y

The target y position

len

The force length, in pixels.

multiplier

Set the force multiplier

Source:

addNewBehavior(behaviorData)

Create the behavior decribed by the given BehaviorData

Parameters:
Name Type Description
behaviorData

The data to be used to construct the behavior.

Returns:
Type Description

true if the behavior was properly created, false otherwise.

Source:

addPolarForce(angle, len, multiplier)

Add a force using polar coordinates.

Parameters:
Name Type Description
angle

The angle of the force, in degrees.

len

The length of the force, in pixels.

multiplier

Set the force multiplier

Source:

averageForceAngleIs(angle, toleranceInDegrees)

Return true if the average angle of the forces applied on the object is in a given range.

Parameters:
Name Type Description
angle

The angle to be tested.

toleranceInDegrees

The length of the range :

Returns:
Type Description

true if the difference between the average angle of the forces and the angle parameter is inferior to toleranceInDegrees parameter.

Source:

behaviorActivated(name)

Check if a behavior is activated

Parameters:
Name Type Description
name

The behavior name.

Returns:
Type Description

true if the behavior is activated.

Source:

clearEffects()

Remove all effects.

Source:

clearForces()

Deletes all forces applied on the object

Source:

cursorOnObject()

Return true if the cursor, or any touch, is on the object.

Returns:
Type Description

true if the cursor, or any touch, is on the object.

Source:

deleteFromScene(runtimeScene)

Remove an object from a scene.

Do not change/redefine this method. Instead, redefine the onDestroyFromScene method.

Parameters:
Name Type Description
runtimeScene

The RuntimeScene owning the object.

Source:

enableEffect(name, enable)

Enable or disable an effect.

Parameters:
Name Type Description
name

The name of the effect to enable or disable.

enable

true to enable, false to disable

Source:

extraInitializationFromInitialInstance(initialInstanceData)

Called when the object is created from an initial instance at the startup of the scene.
Note that common properties (position, angle, z order...) have already been setup.

Parameters:
Name Type Description
initialInstanceData

The data of the initial instance.

Source:

getAABB()

Get the AABB (axis aligned bounding box) for the object.

The default implementation uses either the position/size of the object (when angle is 0) or hitboxes (when angle is not 0) to compute the bounding box. Result is cached until invalidated (by a position change, angle change...).

You should probably redefine updateAABB instead of this function.

Returns:
Type Description

The bounding box

Source:

getAngle()

Get the rotation of the object.

Returns:
Type Description

The rotation of the object, in degrees.

Source:

getAngleToObject(otherObject)

Get the angle, in degrees, from the object center to another object.

Parameters:
Name Type Description
otherObject

The other object

Source:

getAngleToPosition(targetX, targetY)

Get the angle, in degrees, from the object center to a position.

Parameters:
Name Type Description
targetX

Target X position

targetY

Target Y position

Source:

getAverageForce()

Return a force which is the sum of all forces applied on the object.

Returns:
Type Description

A force object.

Source:

getBehavior(name)

Get a behavior from its name. If the behavior does not exists, undefined is returned.

Never keep a reference to a behavior, as they can be hot-reloaded. Instead, always call getBehavior on the object.

Parameters:
Name Type Description
name String

The behavior name.

Returns:
Type Description

The behavior with the given name, or undefined.

Source:

getCenterX()

Return the X position of the object center, relative to the object X position (getDrawableX). Use getCenterXInScene to get the position of the center in the scene.

Returns:
Type Description

the X position of the object center, relative to getDrawableX().

Source:

getCenterXInScene()

Return the X position of the object center, relative to the scene origin.

Returns:
Type Description

the X position of the object center, relative to the scene origin.

Source:

getCenterY()

Return the Y position of the object center, relative to the object position (getDrawableY). Use getCenterYInScene to get the position of the center in the scene.

Returns:
Type Description

the Y position of the object center, relative to getDrawableY().

Source:

getCenterYInScene()

Return the Y position of the object center, relative to the scene origin.

Returns:
Type Description

the Y position of the object center, relative to the scene origin.

Source:

getDistanceToObject(otherObject)

Get the distance, in pixels, between the center of this object and another object.

Parameters:
Name Type Description
otherObject

The other object

Source:

getDistanceToPosition(targetX, targetY)

Get the distance, in pixels, between the center of this object and a position.

Parameters:
Name Type Description
targetX

Target X position

targetY

Target Y position

Source:

getDrawableX()

Get the X position of the rendered object.

For most objects, this will returns the same value as getX(). But if the object has an origin that is not the same as the point (0,0) of the object displayed, getDrawableX will differ.

Returns:
Type Description

The X position of the rendered object.

Source:

getDrawableY()

Get the Y position of the rendered object.

For most objects, this will returns the same value as getY(). But if the object has an origin that is not the same as the point (0,0) of the object displayed, getDrawableY will differ.

Returns:
Type Description

The Y position of the rendered object.

Source:

getElapsedTime(runtimeScene)

Return the time elapsed since the last frame, in milliseconds, for the object.

Objects can have different elapsed time if they are on layers with different time scales.

Parameters:
Name Type Description
runtimeScene

The RuntimeScene the object belongs to (deprecated - can be omitted).

Source:

getHeight()

Return the width of the object.

Returns:
Type Description

The height of the object

Source:

getHitBoxes()

Get the hit boxes for the object.
The default implementation returns a basic bouding box based the size (getWidth and getHeight) and the center point of the object (getCenterX and getCenterY).

You should probably redefine updateHitBoxes instead of this function.

Returns:
Type Description

An array composed of polygon.

Source:

getLayer()

Get the layer of the object.

Returns:
Type Description

The layer of the object

Source:

getName()

Get the name of the object.

Returns:
Type Description

The object's name.

Source:

getNameId()

Get the name identifier of the object.

Returns:
Type Description

The object's name identifier.

Source:

getRendererEffects()

Returns the collection of effects to be rendered by the underlying renderer.

Returns:
Type Description

The renderer effects.

Source:

getRendererObject()

Called with a callback function that should be called with the internal object used for rendering by the object (PIXI.DisplayObject...)

Returns:
Type Description

The internal rendered object (PIXI.DisplayObject...)

Source:

getRuntimeScene()

The gdjs.RuntimeScene the object belongs to.

Source:

getSqDistanceToObject(otherObject)

Get the squared distance, in pixels, between the center of this object and another object.

Parameters:
Name Type Description
otherObject

The other object

Source:

getSqDistanceToPosition(targetX, targetY)

Get the squared distance, in pixels, between the center of this object and a position.

Parameters:
Name Type Description
targetX

Target X position

targetY

Target Y position

Source:

getTimerElapsedTimeInSeconds(timerName)

Get a timer elapsed time.

Parameters:
Name Type Description
timerName

The timer name

Returns:
Type Description

The timer elapsed time in seconds, 0 if the timer doesn't exist

Source:

getUniqueId()

Get the unique identifier of the object.
The identifier is set by the runtimeScene owning the object.
You can also use the id property (this._object.id) for increased efficiency instead of calling this method.

Returns:
Type Description

The object identifier

Source:

getVariables()

Get the container of the object variables

Returns:
Type Description

The variables of the object

Source:

getVisibilityAABB()

Get the AABB (axis aligned bounding box) to be used to determine if the object is visible on screen. The gdjs.RuntimeScene will hide the renderer object if the object is not visible on screen ("culling").

The default implementation uses the AABB returned by getAABB.

If null is returned, the object is assumed to be always visible.

Returns:
Type Description

The bounding box or null.

Source:

getWidth()

Return the width of the object.

Returns:
Type Description

The width of the object

Source:

getX()

Get the X position of the object.

Returns:
Type Description

The X position of the object

Source:

getXFromAngleAndDistance(angle, distance)

Compute the X position when given an angle and distance relative to the starting object. This is also known as getting the cartesian coordinates of a 2D vector, using its polar coordinates.

Parameters:
Name Type Description
angle

The angle, in degrees.

distance

The distance from the object, in pixels

Source:

getY()

Get the Y position of the object.

Returns:
Type Description

The Y position of the object

Source:

getYFromAngleAndDistance(angle, distance)

Compute the Y position when given an angle and distance relative to the starting object. This is also known as getting the cartesian coordinates of a 2D vector, using its polar coordinates.

Parameters:
Name Type Description
angle

The angle, in degrees.

distance

The distance from the object, in pixels

Source:

getZOrder()

Get the Z order of the object.

Returns:
Type Description

The Z order of the object

Source:

hasBehavior(name)

Check if a behavior is used by the object.

Parameters:
Name Type Description
name String

The behavior name.

Source:

hasEffect(name)

Check if an effect exists on this object

Parameters:
Name Type Description
name

The name of the effect

Returns:
Type Description

true if the effect exists, false otherwise.

Source:

hasNoForces()

Return true if no forces are applied on the object.

Returns:
Type Description

true if no forces are applied on the object.

Source:

hasVariable(name)

Shortcut to test if a variable exists for the object.

Parameters:
Name Type Description
name

The variable to be tested

Returns:
Type Description

true if the variable exists.

Source:

hide(enable)

Hide (or show) the object.

Parameters:
Name Type Description
enable

Set it to true to hide the object, false to show it.

Source:

insideObject()

Return true if the specified position is inside object bounding box.

The position should be in "world" coordinates, i.e use gdjs.Layer.convertCoords if you need to pass the mouse or a touch position that you get from gdjs.InputManager.

Source:

isCollidingWithPoint(pointX, pointY)

Check if a point is inside the object collision hitboxes.

Parameters:
Name Type Description
pointX

The point x coordinate.

pointY

The point y coordinate.

Returns:
Type Description

true if the point is inside the object collision hitboxes.

Source:

isEffectEnabled(name)

Check if an effect is enabled

Parameters:
Name Type Description
name

The name of the effect

Returns:
Type Description

true if the effect is enabled, false otherwise.

Source:

isHidden()

Return true if the object is hidden.

Returns:
Type Description

true if the object is hidden.

Source:

isOnLayer(layer)

Return true if the object is on the specified layer

Parameters:
Name Type Description
layer

The layer to be tested.

Returns:
Type Description

true if the object is on the specified layer

Source:

isVisible()

Return true if the object is not hidden.

Note: This is unrelated to the actual visibility of the object on the screen. For this, see getVisibilityAABB to get the bounding boxes of the object as displayed on the scene.

Returns:
Type Description

true if the object is not hidden.

Source:

notifyBehaviorsObjectHotReloaded()

Called when the object was hot reloaded, to notify behaviors that the object was modified. Useful for behaviors that

Source:

onCreated()

To be called by the child classes in their constructor, at the very end. Notify the behaviors that they have been constructed (this must be done when the object is ready, otherwise behaviors can do operations on the object which could be not initialized yet).

If you redefine this function, make sure to call the original method (RuntimeObject.prototype.onCreated.call(this);).

Source:

onDestroyFromScene(runtimeScene)

Called when the object is destroyed (because it is removed from a scene or the scene is being unloaded). If you redefine this function, make sure to call the original method (RuntimeObject.prototype.onDestroyFromScene.call(this, runtimeScene);).

Parameters:
Name Type Description
runtimeScene

The scene owning the object.

Source:

pauseTimer(timerName)

Pause a timer, if the timer doesn't exist it is created

Parameters:
Name Type Description
timerName

The timer name

Source:

putAround(x, y, distance, angleInDegrees)

Put the object around a position, with a specific distance and angle. The distance and angle are computed between the position and the center of the object.

Parameters:
Name Type Description
x

The x position of the target

y

The y position of the target

distance

The distance between the object and the target, in pixels.

angleInDegrees

The angle between the object and the target, in degrees.

Source:

putAroundObject(obj, distance, angleInDegrees)

Put the object around another object, with a specific distance and angle. The distance and angle are computed between the centers of the objects.

Parameters:
Name Type Description
obj

The target object

distance

The distance between the object and the target

angleInDegrees

The angle between the object and the target, in degrees.

Source:

raycastTest(x, y, endX, endY, closest)

Parameters:
Name Type Description
x

The raycast source X

y

The raycast source Y

endX

The raycast end position X

endY

The raycast end position Y

closest

Get the closest or farthest collision mask result?

Returns:
Type Description

A raycast result with the contact points and distances

Source:

reinitialize()

Called to reset the object to its default state. This is used for objects that are "recycled": they are dismissed (at which point onDestroyFromScene is called) but still stored in a cache to be reused next time an object must be created. At this point, reinitialize will be called. The object must then work as if it was a newly constructed object.

To implement this in your object:

  • Set gdjs.YourRuntimeObject.supportsReinitialization = true; to declare support for recycling.
  • Implement reinitialize. It must call the reinitialize of gdjs.RuntimeObject, and call this.onCreated(); at the end of reinitizalize.
  • It must reset the object as if it was newly constructed (be careful about your renderers and any global state).
  • The _runtimeScene, _nameId, name and type are guaranteed to stay the same and do not need to be set again.
Source:

removeBehavior(name)

Remove the behavior with the given name. Usually only used by hot-reloading, as performance of this operation is not guaranteed (in the future, this could lead to re-organization of arrays holding behaviors).

Parameters:
Name Type Description
name

The name of the behavior to remove.

Returns:
Type Description

true if the behavior was properly removed, false otherwise.

Source:

removeEffect(effectName)

Remove the effect with the specified name

Parameters:
Name Type Description
effectName

The name of the effect.

Source:

removeTimer(timerName)

Remove a timer

Parameters:
Name Type Description
timerName

The timer name

Source:

resetTimer(timerName)

Reset a timer, if the timer doesn't exist it is created

Parameters:
Name Type Description
timerName

The timer name

Source:

rotate(speed, runtimeScene)

Rotate the object at the given speed

Parameters:
Name Type Description
speed

The speed, in degrees per second.

runtimeScene

The scene where the object is displayed.

Source:

separateFromObjects(objects, ignoreTouchingEdges)

Separate the object from others objects, using their hitboxes.

Parameters:
Name Type Description
objects

Objects

ignoreTouchingEdges

If true, then edges that are touching each other, without the hitbox polygons actually overlapping, won't be considered in collision.

Returns:
Type Description

true if the object was moved

Source:

separateFromObjectsList(objectsLists, ignoreTouchingEdges)

Separate the object from others objects, using their hitboxes.

Parameters:
Name Type Description
objectsLists

Tables of objects

ignoreTouchingEdges

If true, then edges that are touching each other, without the hitbox polygons actually overlapping, won't be considered in collision.

Returns:
Type Description

true if the object was moved

Source:

separateObjectsWithForces(objectsLists)

Parameters:
Name Type Description
objectsLists

Tables of objects

Deprecated:
  • Yes

Source:

separateObjectsWithoutForces(objectsLists)

Parameters:
Name Type Description
objectsLists

Tables of objects

Deprecated:
  • Yes

Source:

setAngle(angle)

Set the angle of the object.

Parameters:
Name Type Description
angle

The new angle of the object

Source:

setCenterPositionInScene(x, y)

Change the object center position in the scene.

Parameters:
Name Type Description
x

The new X position of the center in the scene.

y

The new Y position of the center in the scene.

Source:

setCenterXInScene(x)

Change the object center X position in the scene.

Parameters:
Name Type Description
x

The new X position of the center in the scene.

Source:

setCenterYInScene(x)

Change the object center Y position in the scene.

Parameters:
Name Type Description
x

The new Y position of the center in the scene.

Source:

setEffectBooleanParameter(name, parameterName, value)

Change an effect parameter value (for parameters that are booleans).

Parameters:
Name Type Description
name

The name of the effect to update.

parameterName

The name of the parameter to update.

value

The new value (boolean).

Source:

setEffectDoubleParameter(name, parameterName, value)

Change an effect parameter value (for parameters that are numbers).

Parameters:
Name Type Description
name

The name of the effect to update.

parameterName

The name of the parameter to update.

value

The new value (number).

Source:

setEffectStringParameter(name, parameterName, value)

Change an effect parameter value (for parameters that are strings).

Parameters:
Name Type Description
name

The name of the effect to update.

parameterName

The name of the parameter to update.

value

The new value (string).

Source:

setHeight(height)

Set the height of the object, if applicable.

Parameters:
Name Type Description
height

The new height in pixels.

Source:

setLayer(layer)

Set the layer of the object.

Parameters:
Name Type Description
layer

The new layer of the object

Source:

setPosition(x, y)

Set the position of the object.

Parameters:
Name Type Description
x

The new X position

y

The new Y position

Source:

setWidth(width)

Set the width of the object, if applicable.

Parameters:
Name Type Description
width

The new width in pixels.

Source:

setX(x)

Set the X position of the object.

Parameters:
Name Type Description
x

The new X position

Source:

setY(y)

Set the Y position of the object.

Parameters:
Name Type Description
y

The new Y position

Source:

setZOrder(z)

Set the Z order of the object.

Parameters:
Name Type Description
z

The new Z order position of the object

Source:

stepBehaviorsPostEvents()

Call each behavior stepPostEvents method.

Source:

stepBehaviorsPreEvents()

Call each behavior stepPreEvents method.

Source:

timerElapsedTime(timerName, timeInSeconds)

Test a timer elapsed time, if the timer doesn't exist it is created

Parameters:
Name Type Description
timerName

The timer name

timeInSeconds

The time value to check in seconds

Returns:
Type Description

True if the timer exists and its value is greater than or equal than the given time, false otherwise

Source:

timerPaused(timerName)

Test a if a timer is paused

Parameters:
Name Type Description
timerName

The timer name

Returns:
Type Description

True if the timer exists and is paused, false otherwise

Source:

unpauseTimer(timerName)

Unpause a timer, if the timer doesn't exist it is created

Parameters:
Name Type Description
timerName

The timer name

Source:

update(runtimeScene)

Called once during the game loop, before events and rendering.

Parameters:
Name Type Description
runtimeScene

The gdjs.RuntimeScene the object belongs to.

Source:

updateAABB()

Update the AABB (axis aligned bounding box) for the object.

Default implementation uses either the position/size of the object (when angle is 0) or hitboxes (when angle is not 0) to compute the bounding box.

You should not call this function by yourself, it is called when necessary by getAABB method. However, you can redefine it if your object can have a faster implementation.

Source:

updateAllEffectParameters(effectData)

Updates all the parameters of an effect.

Parameters:
Name Type Description
effectData

The data describing the effect

Source:

updateForces()

Called once a step by runtimeScene to update forces magnitudes and remove null ones.

Source:

updateFromObjectData(oldObjectData, newObjectData)

Called when the object must be updated using the specified objectData. This is the case during hot-reload, and is only called if the object was modified.

Parameters:
Name Type Description
oldObjectData

The previous data for the object.

newObjectData

The new data for the object.

Returns:
Type Description

true if the object was updated, false if it could not (i.e: hot-reload is not supported).

Source:

updateHitBoxes()

Update the hit boxes for the object.

The default implementation set a basic bounding box based on the size (getWidth and getHeight) and the center point of the object (getCenterX and getCenterY). Result is cached until invalidated (by a position change, angle change...).

You should not call this function by yourself, it is called when necessary by getHitBoxes method. However, you can redefine it if your object need custom hit boxes.

Source:

updatePreRender(runtimeScene)

Called once during the game loop, after events and before rendering.

Parameters:
Name Type Description
runtimeScene

The gdjs.RuntimeScene the object belongs to.

Source:

updateTimers(elapsedTime)

Updates the object timers. Called once during the game loop, before events and rendering.

Parameters:
Name Type Description
elapsedTime

The elapsed time since the previous frame in milliseconds.

Source: