Base class for 3D objects.

Hierarchy (view full)

Implements

Constructors

Properties

Methods

activateBehavior addEffect addForce addForceTowardObject addForceTowardPosition addNewBehavior addPolarForce averageForceAngleIs behaviorActivated clearEffects clearForces collisionTest cursorOnObject deleteFromScene distanceTest enableEffect extraInitializationFromInitialInstance flipX flipY flipZ get3DRendererObject getAABB getAABBBottom getAABBCenterX getAABBCenterY getAABBLeft getAABBRight getAABBTop getAngle getAngleToObject getAngleToPosition getAverageForce getBehavior getCenterX getCenterXInScene getCenterY getCenterYInScene getCenterZ getCenterZInScene getDepth getDistanceToObject getDistanceToPosition getDrawableX getDrawableY getDrawableZ getElapsedTime getEstimatedVelocityX getEstimatedVelocityY getEstimatedVelocityZ getForwardX getForwardY getForwardZ getHeight getHitBoxes getHitBoxesAround getInstanceContainer getLayer getName getNameId getNameIdentifier getNetworkId getNetworkSyncData getOriginalDepth getOriginalHeight getOriginalWidth getParent getRenderer getRendererEffects getRendererObject getRightX getRightY getRightZ getRotationX getRotationY getRuntimeScene getScale getScaleX getScaleY getScaleZ getSqDistanceToObject getSqDistanceToPosition getTimerElapsedTimeInSeconds getTimerElapsedTimeInSecondsOrNaN getUniqueId getUnrotatedAABBMaxZ getUnrotatedAABBMinZ getUpX getUpY getUpZ getVariableChildCount getVariableNumber getVariableString getVariables getVisibilityAABB getWidth getX getXFromAngleAndDistance getY getYFromAngleAndDistance getZ getZOrder hasBehavior hasEffect hasEstimatedVelocity hasNoForces hasVariable hide insideObject invalidateHitboxes isCollidingWithPoint isEffectEnabled isFlippedX isFlippedY isFlippedZ isHidden isIncludedInParentCollisionMask isOnLayer isSpatiallyIndexed isTotalForceAngleAround isVisible notifyBehaviorsObjectHotReloaded onCreated onDeletedFromScene onDestroyed onScenePaused onSceneResumed pauseTimer putAround putAroundObject raycastTest registerDestroyCallback reinitialize removeBehavior removeEffect removeTimer resetEstimatedVelocity resetTimer returnVariable rotate rotateTowardAngle rotateTowardObject rotateTowardPosition separateFromObjects separateFromObjectsList separateObjectsWithForces separateObjectsWithoutForces setAngle setCenterPositionInScene setCenterXInScene setCenterYInScene setCenterZInScene setDepth setEffectBooleanParameter setEffectDoubleParameter setEffectStringParameter setEstimatedVelocityX setEstimatedVelocityY setEstimatedVelocityZ setHeight setIncludedInParentCollisionMask setLayer setPosition setRotationX setRotationY setScale setScaleX setScaleY setScaleZ setSize setVariableNumber setVariableString setWidth setX setY setZ setZOrder stepBehaviorsPostEvents stepBehaviorsPreEvents timerElapsedTime timerPaused turnAroundX turnAroundY turnAroundZ unpauseTimer unregisterDestroyCallback update updateAABB updateAllEffectParameters updateForces updateFromNetworkSyncData updateFromObjectData updateHitBoxes updateOriginalDimensionsFromObjectData updatePreRender updateTimers

Constructors

Properties

angle: number = 0
forcesGarbage: Force[] = []

Global container for unused forces, avoiding recreating forces each tick.

Static

getFirstVariableNumber: ((array) => number) = ...

Shortcut to get the first value of an array variable as a number.

Type declaration

    • (array): number
    • Parameters

      Returns number

getFirstVariableNumber: ((array) => number) = RuntimeObject.getFirstVariableNumber

Type declaration

    • (array): number
    • Shortcut to get the first value of an array variable as a number.

      Parameters

      Returns number

getFirstVariableString: ((array) => string) = ...

Shortcut to get the first value of an array variable as a string.

Type declaration

    • (array): string
    • Parameters

      Returns string

getFirstVariableString: ((array) => string) = RuntimeObject.getFirstVariableString

Type declaration

    • (array): string
    • Shortcut to get the first value of an array variable as a string.

      Parameters

      Returns string

getLastVariableNumber: ((array) => number) = ...

Shortcut to get the last value of an array variable as a number.

Type declaration

    • (array): number
    • Parameters

      Returns number

getLastVariableNumber: ((array) => number) = RuntimeObject.getLastVariableNumber

Type declaration

    • (array): number
    • Shortcut to get the last value of an array variable as a number.

      Parameters

      Returns number

getLastVariableString: ((array) => string) = ...

Shortcut to get the last value of an array variable as a string.

Type declaration

    • (array): string
    • Parameters

      Returns string

getLastVariableString: ((array) => string) = RuntimeObject.getLastVariableString

Type declaration

    • (array): string
    • Shortcut to get the last value of an array variable as a string.

      Parameters

      Returns string

getSqDistanceTo: ((targetX, targetY) => number) = RuntimeObject.prototype.getSqDistanceToPosition

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

Type declaration

    • (targetX, targetY): number
    • Parameters

      • targetX: number
      • targetY: number

      Returns number

Deprecated

Use getSqDistanceToPosition instead.

getVariableBoolean: ((variable, compareWith) => boolean) = RuntimeObject.getVariableBoolean

Type declaration

    • (variable, compareWith): boolean
    • Private

      Shortcut to compare the value of a variable considered as a boolean. This shortcut function is needed for events code generation.

      Parameters

      Returns boolean

getVariableChildCount: ((variable) => number) = RuntimeObject.getVariableChildCount

Type declaration

    • (variable): number
    • Get the number of children from a variable

      Parameters

      • variable: Variable

        The variable to be accessed

      Returns number

      The number of children

      Static

getVariableNumber: ((variable) => number) = RuntimeObject.getVariableNumber

Type declaration

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

      Parameters

      • variable: Variable

        The variable to be accessed

      Returns number

      The value of the specified variable

      Static

getVariableString: ((variable) => string) = RuntimeObject.getVariableString

Type declaration

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

      Parameters

      • variable: Variable

        The variable to be accessed

      Returns string

      The string of the specified variable

      Static

hidden: boolean = false
id: number
layer: string = ''
name: string
networkId: null | string = null

A network ID associated to the object to be used for multiplayer, to identify the object across peers. We don't use persistentUuid as it's only used for hot-reload. We don't use the object ID either as it's not unique across peers.

persistentUuid: null | string = null

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

pick: boolean = false

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.

returnVariable: ((variable) => Variable) = RuntimeObject.returnVariable

Type declaration

    • (variable): Variable
    • Return the variable passed as argument without any change. Only for usage by events.

      Parameters

      • variable: Variable

        The variable to be accessed

      Returns Variable

      The specified variable

      Static

setVariableBoolean: ((variable, newValue) => void) = RuntimeObject.setVariableBoolean

Type declaration

    • (variable, newValue): void
    • Private

      Shortcut to set the value of a variable considered as a boolean. This shortcut function is needed for events code generation.

      Parameters

      Returns void

setVariableNumber: ((variable, newValue) => void) = RuntimeObject.setVariableNumber

Type declaration

    • (variable, newValue): void
    • Shortcut to set the value of a variable considered as a number

      Parameters

      • variable: Variable

        The variable to be changed

      • newValue: number

        The value to be set

      Returns void

setVariableString: ((variable, newValue) => void) = RuntimeObject.setVariableString

Type declaration

    • (variable, newValue): void
    • Shortcut to set the value of a variable considered as a string

      Parameters

      • variable: Variable

        The variable to be changed

      • newValue: string

        {String} The value to be set

      Returns void

supportsReinitialization: boolean = false
toggleVariableBoolean: ((variable) => void) = RuntimeObject.toggleVariableBoolean

Type declaration

    • (variable): void
    • Private

      Toggles a variable. This shortcut function is needed for events code generation.

      Parameters

      Returns void

      See

type: string
valuePush: ((array, value) => void) = RuntimeObject.valuePush

Type declaration

    • (array, value): void
    • Private

      This shortcut function is needed for events code generation.

      Parameters

      • array: Variable
      • value: string | number | boolean

      Returns void

variableChildExists: ((variable, childName) => boolean) = RuntimeObject.variableChildExists

Type declaration

    • (variable, childName): boolean
    • Parameters

      • variable: Variable

        The variable to be tested

      • childName: string

        The name of the child

      Returns boolean

variableClearChildren: ((variable) => void) = RuntimeObject.variableClearChildren

Type declaration

    • (variable): void
    • Parameters

      • variable: Variable

        The variable to be cleared

      Returns void

variablePushCopy: ((array, variable) => void) = RuntimeObject.variablePushCopy

Type declaration

    • (array, variable): void
    • Private

      This shortcut function is needed for events code generation.

      Parameters

      Returns void

variableRemoveAt: ((array, index) => void) = RuntimeObject.variableRemoveAt

Type declaration

    • (array, index): void
    • Private

      This shortcut function is needed for events code generation.

      Parameters

      Returns void

variableRemoveChild: ((variable, childName) => void) = RuntimeObject.variableRemoveChild

Type declaration

    • (variable, childName): void
    • Parameters

      • variable: Variable

        The variable to be changed

      • childName: string

        The name of the child

      Returns void

x: number = 0
y: number = 0
zOrder: number = 0
aabb: AABB = ...
hitBoxes: Polygon[]
hitBoxesDirty: boolean = true
getVariableBoolean: ((variable, compareWith) => boolean) = ...

Shortcut to compare the value of a variable considered as a boolean. This shortcut function is needed for events code generation.

Type declaration

    • (variable, compareWith): boolean
    • Parameters

      Returns boolean

Returns

setVariableBoolean: ((variable, newValue) => void) = ...

Shortcut to set the value of a variable considered as a boolean. This shortcut function is needed for events code generation.

Type declaration

    • (variable, newValue): void
    • Parameters

      Returns void

toggleVariableBoolean: ((variable) => void) = ...

Toggles a variable. This shortcut function is needed for events code generation.

Type declaration

    • (variable): void
    • Parameters

      Returns void

See

valuePush: ((array, value) => void) = ...

This shortcut function is needed for events code generation.

Type declaration

    • (array, value): void
    • Parameters

      • array: Variable
      • value: string | number | boolean

      Returns void

variablePushCopy: ((array, variable) => void) = ...

This shortcut function is needed for events code generation.

Type declaration

variableRemoveAt: ((array, index) => void) = ...

This shortcut function is needed for events code generation.

Type declaration

    • (array, index): void
    • Parameters

      Returns void

Methods

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

    Parameters

    • angle: number

      The angle to be tested.

    • toleranceInDegrees: number

      The length of the range :

    Returns boolean

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

    Deprecated

    Use isTotalForceAngleAround instead.

  • Return true if the hitboxes of two objects are overlapping

    Parameters

    • obj1: RuntimeObject

      The first runtimeObject

    • obj2: RuntimeObject

      The second runtimeObject

    • ignoreTouchingEdges: boolean

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

    • ignoredObject1Polygon: null | Polygon = null

      A polygon from the obj1 collision mask to ignore

    Returns boolean

    true if obj1 and obj2 are in collision

    Static

  • 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 AABB

    The bounding box

  • Return the Z position of the object center, relative to the object Z position (getDrawableX).

    Use getCenterZInScene to get the position of the center in the scene.

    Returns number

    the Z position of the object center, relative to getDrawableZ().

  • Get the Z position of the rendered object.

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

    Returns number

    The Z position of the rendered object.

  • Return at least all the hit boxes that overlap a given area.

    The hit boxes don't need to actually overlap the area, (i.e: it's correct to return more hit boxes than those in the specified area) but the ones that do must be returned.

    The default implementation returns the same as getHitBoxes.

    This method can be overridden by grid based objects (or other objects that can quickly compute which hitboxes are touching a given area) to optimize collision checks.

    When overriding this method, the following ones should be overridden too:

    Parameters

    • left: number

      bound of the area in scene coordinates

    • top: number

      bound of the area in scene coordinates

    • right: number

      bound of the area in scene coordinates

    • bottom: number

      bound of the area in scene coordinates

    Returns Iterable<Polygon>

    at least all the hit boxes that overlap a given area.

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

    Parameters

    • name: string

    Returns number

    Static

  • 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. To check if a point is inside the object collision mask, you can use isCollidingWithPoint instead.

    Parameters

    • x: number
    • y: number

    Returns boolean

  • 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);).

    Returns void

  • 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

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

    Returns void

  • Called to reset the object to its default state. This is used for objects that are "recycled": they are dismissed (at which point onDeletedFromScene 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 reinitialize.
    • 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.

    Parameters

    • objectData: ObjectData

    Returns void

  • 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: string

      The name of the behavior to remove.

    Returns boolean

    true if the behavior was properly removed, false otherwise.

  • Compare a timer elapsed time. If the timer does not exist, it is created.

    Parameters

    • timerName: string

      The timer name.

    • timeInSeconds: number

      The time value to check in seconds.

    Returns boolean

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

    Deprecated

    prefer using getTimerElapsedTimeInSecondsOrNaN.

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

    Returns void

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

    Returns void