Class: SpriteRuntimeObject

SpriteRuntimeObject

new gdjs.SpriteRuntimeObject(runtimeScene, spriteObjectData)

The SpriteRuntimeObject represents an object that can display images.

Name Type Description
runtimeScene gdjs.RuntimeScene

The scene the object belongs to

spriteObjectData SpriteObjectData

The object data used to initialize the object

Extends

Members

protectedaabbAABB

protectedanglenumber

protectedhiddenboolean

protectedhitBoxesArray.<gdjs.Polygon>

protectedhitBoxesDirtyboolean

protectedidnumber

protectedlayerstring

protectednamestring

opacitynumber

protectedtypestring

protectedxnumber

protectedynumber

protectedzOrdernumber

inneranimDataSpriteAnimationData

Methods

inherited activateBehavior(name, enable)

De/activate a behavior of the object.

Name Type Description
name String

The behavior name.

enable boolean

true to activate the behavior

inherited addForce(x, y, multiplier)

Add a force to the object to move it.

Name Type Description
x number

The x coordinates of the force

y number

The y coordinates of the force

multiplier number

Set the force multiplier

inherited addForceTowardObject(object, len, multiplier)

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

Name Type Description
object gdjs.RuntimeObject

The target object

len number

The force length, in pixels.

multiplier number

Set the force multiplier

inherited addForceTowardPosition(x, y, len, multiplier)

Add a force oriented toward a position

Name Type Description
x number

The target x position

y number

The target y position

len number

The force length, in pixels.

multiplier number

Set the force multiplier

inherited addPolarForce(angle, len, multiplier)

Add a force using polar coordinates.

Name Type Description
angle number

The angle of the force, in degrees.

len number

The length of the force, in pixels.

multiplier number

Set the force multiplier

inherited averageForceAngleIs(angle, toleranceInDegrees){boolean}

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

Name Type Description
angle number

The angle to be tested.

toleranceInDegrees number

The length of the range :

Returns:
Type Description
boolean true if the difference between the average angle of the forces and the angle parameter is inferior to toleranceInDegrees parameter.

inherited behaviorActivated(name)

Check if a behavior is activated

Name Type Description
name String

The behavior name.

Returns:
true if the behavior is activated.

Deletes all forces applied on the object

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

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

inherited deleteFromScene(runtimeScene)

Remove an object from a scene.

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

Name Type Description
runtimeScene gdjs.RuntimeScene

The RuntimeScene owning the object.

extraInitializationFromInitialInstance(initialInstanceData)

Initialize the extra parameters that could be set for an instance.

Name Type Description
initialInstanceData Object

The extra parameters

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
AABB The bounding box (example: {min: [10,5], max:[20,10]})

getAngle(){number}

Get the angle of the object.

Returns:
Type Description
number The angle, in degrees.

getAnimation(){number}

Get the index of the animation being played.

Returns:
Type Description
number The index of the new animation being played

getAnimationFrame(){number}

Get the index of the current frame displayed by the animation

Returns:
Type Description
number newFrame The index of the frame being displayed

getAnimationName(){string}

Get the name of the animation being played.

Returns:
Type Description
string The name of the new animation being played

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

Returns:
Type Description
gdjs.Force A force object.

Get a behavior from its name.

Be careful, the behavior must exists, no check is made on the name.

Name Type Description
name String

The behavior name.

Returns:
Type Description
gdjs.RuntimeBehavior The behavior with the given name, or undefined.

getCenterX(){number}

Get the X position of the center of the object, relative to top-left of the texture of the object (getDrawableX).

Returns:
Type Description
number X position of the center of the object, relative to getDrawableX().

getCenterY(){number}

Get the Y position of the center of the object, relative to top-left of the texture of the object (getDrawableY).

Returns:
Type Description
number Y position of the center of the object, relative to getDrawableY().

getColor(){string}

Get the tint of the sprite object.

Returns:
Type Description
string rgbColor The color, in RGB format ("128;200;255").

inherited getDistanceToObject(otherObject)

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

Name Type Description
otherObject gdjs.RuntimeObject

The other object

getDrawableX(){number}

Get the X position, on the scene, of the origin of the texture of the object.

Returns:
Type Description
number the X position, on the scene, of the origin of the texture of the object.

getDrawableY(){number}

Get the Y position, on the scene, of the origin of the texture of the object.

Returns:
Type Description
number the Y position, on the scene, of the origin of the texture of the object.

inherited 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.

Name Type Description
runtimeScene gdjs.RuntimeScene

The RuntimeScene the object belongs to.

getHeight(){number}

Get the height of the object.

Returns:
Type Description
number The height of the object, in pixels.

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
Array.<gdjs.Polygon> An array composed of polygon.

inherited getLayer(){string}

Get the layer of the object.

Returns:
Type Description
string The layer of the object

inherited getName(){string}

Get the name of the object.

Returns:
Type Description
string The object's name.

inherited getNameId(){number}

Get the name identifier of the object.

Returns:
Type Description
number The object's name identifier.

getOpacity(){number}

Get the transparency of the object.

Returns:
Type Description
number The opacity, between 0 (transparent) and 255 (opaque).

getPointX(name){number}

Get the position on X axis on the scene of the given point.

Name Type Description
name string

The point name

Returns:
Type Description
number the position on X axis on the scene of the given point.

getPointY(name){number}

Get the position on Y axis on the scene of the given point.

Name Type Description
name string

The point name

Returns:
Type Description
number the position on Y axis on the scene of the given point.

inherited getRendererObject(){Object}

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

Returns:
Type Description
Object The internal rendered object (PIXI.DisplayObject...)

getScale(){number}

Get the scale of the object (or the average of the X and Y scale in case they are different).

Returns:
Type Description
number the scale of the object (or the average of the X and Y scale in case they are different).

getScaleX(){number}

Get the scale of the object on X axis.

Returns:
Type Description
number the scale of the object on X axis

getScaleY(){number}

Get the scale of the object on Y axis.

Returns:
Type Description
number the scale of the object on Y axis

inherited getSqDistanceTo(pointX, pointY)

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

Name Type Description
pointX number

X position

pointY number

Y position

inherited getSqDistanceToObject(otherObject)

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

Name Type Description
otherObject gdjs.RuntimeObject

The other object

inherited getTimerElapsedTimeInSeconds(timerName){number}

Get a timer elapsed time.

Name Type Description
timerName String

The timer name

Returns:
Type Description
number The timer elapsed time in seconds, 0 if the timer doesn't exist

inherited getUniqueId(){number}

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
number The object identifier

Get the container of the object variables

Returns:
Type Description
gdjs.VariablesContainer The variables of the object

inherited getVisibilityAABB(){AABB}

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
AABB The bounding box (example: {min: [10,5], max:[20,10]}) or null.

getWidth(){number}

Get the width of the object.

Returns:
Type Description
number The width of the object, in pixels.

Get the X position of the object.

Returns:
Type Description
number The X position of the object

Get the Y position of the object.

Returns:
Type Description
number The Y position of the object

inherited getZOrder(){number}

Get the Z order of the object.

Returns:
Type Description
number The Z order of the object

hasAnimationEnded()

Return true if animation has ended.

inherited hasBehavior(name)

Check if a behavior is used by the object.

Name Type Description
name String

The behavior name.

inherited hasNoForces(){boolean}

Return true if no forces are applied on the object.

Returns:
Type Description
boolean true if no forces are applied on the object.

inherited hasVariable(name){boolean}

Shortcut to test if a variable exists for the object.

Name Type Description
name string

The variable to be tested

Returns:
Type Description
boolean true if the variable exists.

Hide (or show) the object

Name Type Description
enable boolean

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

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.

inherited isCollidingWithPoint(pointX, pointY)

Check if a point is inside the object collision hitboxes.

Name Type Description
pointX

The point x coordinate.

pointY

The point y coordinate.

Returns:
true if the point is inside the object collision hitboxes.

inherited isHidden(){boolean}

Return true if the object is hidden.

Returns:
Type Description
boolean true if the object is hidden.

inherited isOnLayer(layer){boolean}

Return true if the object is on the specified layer

Name Type Description
layer string

The layer to be tested.

Returns:
Type Description
boolean true if the object is on the specified layer

inherited isVisible(){boolean}

Return true if the object is not hidden.

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

Returns:
Type Description
boolean true if the object is not hidden.

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 (gdjs.RuntimeObject.prototype.onCreated.call(this);).

inherited 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 (gdjs.RuntimeObject.prototype.onDestroyFromScene.call(this, runtimeScene);).

Name Type Description
runtimeScene gdjs.RuntimeScene

The scene owning the object.

inherited pauseTimer(timerName)

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

Name Type Description
timerName String

The timer name

inherited 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.

Name Type Description
x number

The x position of the target

y number

The y position of the target

distance number

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

angleInDegrees number

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

inherited 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.

Name Type Description
obj

The target object

distance number

The distance between the object and the target

angleInDegrees number

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

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

Name Type Description
x number

The raycast source X

y number

The raycast source Y

endX number

The raycast end position X

endY number

The raycast end position Y

closest boolean

Get the closest or farthest collision mask result?

Returns:
A raycast result with the contact points and distances

inherited removeTimer(timerName)

Remove a timer

Name Type Description
timerName String

The timer name

inherited resetTimer(timerName)

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

Name Type Description
timerName String

The timer name

inherited rotate(speed, runtimeScene)

Rotate the object at the given speed

Name Type Description
speed number

The speed, in degrees per second.

runtimeScene gdjs.RuntimeScene

The scene where the object is displayed.

inherited separateFromObjects(objects, ignoreTouchingEdges)

Separate the object from others objects, using their hitboxes.

Name Type Description
objects

Objects

ignoreTouchingEdges boolean | undefined

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

Returns:
true if the object was moved

inherited separateFromObjectsList(objectsLists, ignoreTouchingEdges)

Separate the object from others objects, using their hitboxes.

Name Type Description
objectsLists

Tables of objects

ignoreTouchingEdges boolean | undefined

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

Returns:
true if the object was moved

inherited separateObjectsWithForces(objectsLists)

Name Type Description
objectsLists

Tables of objects

Deprecated
  • Yes

inherited separateObjectsWithoutForces(objectsLists)

Name Type Description
objectsLists

Tables of objects

Deprecated
  • Yes

setAngle(angle)

Set the angle of the object.

Name Type Description
angle number

The new angle, in degrees.

setAnimation(newAnimation)

Change the animation being played.

Name Type Description
newAnimation number

The index of the new animation to be played

setAnimationFrame(newFrame)

Change the current frame displayed by the animation

Name Type Description
newFrame number

The index of the frame to be displayed

setAnimationName(newAnimationName)

Change the animation being played.

Name Type Description
newAnimationName string

The name of the new animation to be played

setColor(rgbColor)

Change the tint of the sprite object.

Name Type Description
rgbColor string

The color, in RGB format ("128;200;255").

setDirectionOrAngle(){number}

Change the angle (or direction index) of the object

Returns:
Type Description
number The new angle (or direction index) to be applied

setHeight(height)

Change the height of the object. This changes the scale on Y axis of the object.

Name Type Description
height number

The new height of the object, in pixels.

Set the layer of the object.

Name Type Description
layer string

The new layer of the object

setOpacity(opacity)

Change the transparency of the object.

Name Type Description
opacity number

The new opacity, between 0 (transparent) and 255 (opaque).

inherited setPosition(x, y)

Set the position of the object.

Name Type Description
x number

The new X position

y number

The new Y position

setScale(newScale)

Change the scale on X and Y axis of the object.

Name Type Description
newScale number

The new scale (must be greater than 0).

setScaleX(newScale)

Change the scale on X axis of the object (changing its width).

Name Type Description
newScale number

The new scale (must be greater than 0).

setScaleY(newScale)

Change the scale on Y axis of the object (changing its width).

Name Type Description
newScale number

The new scale (must be greater than 0).

setWidth(width)

Change the width of the object. This changes the scale on X axis of the object.

Name Type Description
width number

The new width of the object, in pixels.

Set the X position of the (origin of the) object.

Name Type Description
x number

The new X position.

Set the Y position of the (origin of the) object.

Name Type Description
y number

The new Y position.

Set the Z order of the object.

Name Type Description
z number

The new Z order position of the object

inherited stepBehaviorsPostEvents()

Call each behavior stepPostEvents method.

inherited stepBehaviorsPreEvents()

Call each behavior stepPreEvents method.

inherited timerElapsedTime(timerName, timeInSeconds){boolean}

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

Name Type Description
timerName String

The timer name

timeInSeconds number

The time value to check in seconds

Returns:
Type Description
boolean True if the timer exists and its value is greater than or equal than the given time, false otherwise

inherited timerPaused(timerName){boolean}

Test a if a timer is paused

Name Type Description
timerName String

The timer name

Returns:
Type Description
boolean True if the timer exists and is paused, false otherwise

turnTowardObject(obj, scene)

Name Type Description
obj

The target object

scene

The scene containing the object

Deprecated
  • Yes

inherited unpauseTimer(timerName)

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

Name Type Description
timerName String

The timer name

Update the current frame of the object according to the elapsed time on the scene.

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.

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

updateHitBoxes()

Update the hit boxes for the object. Fallback to the default implementation (rotated bounding box) if there is no custom hitboxes defined for the current animation frame.

inherited updateTimers(elapsedTime)

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

Name Type Description
elapsedTime number

The elapsed time since the previous frame in milliseconds.