Options
All
  • Public
  • Public/Protected
  • All
Menu

The SpriteRuntimeObject represents an object that can display images.

Hierarchy

Implements

Index

Methods

Properties

Constructors

Methods

  • activateBehavior(name: string, enable: boolean): void
  • addEffect(effectData: EffectData): boolean
  • addForce(x: number, y: number, multiplier: number): void
  • addForceTowardObject(object: null | RuntimeObject, len: number, multiplier: number): void
  • addForceTowardPosition(x: number, y: number, len: number, multiplier: number): void
  • addNewBehavior(behaviorData: BehaviorData): boolean
  • addPolarForce(angle: number, len: number, multiplier: number): void
  • animationPaused(): boolean
  • averageForceAngleIs(angle: number, toleranceInDegrees: number): boolean
  • Return true if the average angle of the forces applied on the object is in a given range.

    deprecated

    Use isTotalForceAngleAround instead.

    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.

  • behaviorActivated(name: string): boolean
  • clearEffects(): boolean
  • clearForces(): void
  • Return true if the hitboxes of two objects are overlapping

    static

    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

  • enableEffect(name: string, enable: boolean): void
  • extraInitializationFromInitialInstance(initialInstanceData: InstanceData): void
  • flipX(enable: boolean): void
  • flipY(enable: boolean): void
  • get3DRendererObject(): undefined | null | Object3D<Object3DEventMap>
  • 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

  • getAABBBottom(): number
  • getAABBCenterX(): number
  • getAABBCenterY(): number
  • getAABBLeft(): number
  • getAABBRight(): number
  • getAABBTop(): number
  • getAngle(): number
  • getAngleToPosition(targetX: number, targetY: number): number
  • getAnimation(): number
  • getAnimationDuration(): number
  • getAnimationElapsedTime(): number
  • getAnimationFrame(): number
  • getAnimationFrameCount(): number
  • getAnimationIndex(): number
  • getAnimationName(): string
  • getAnimationSpeedScale(): number
  • 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: string

      The behavior name.

    Returns null | RuntimeBehavior

    The behavior with the given name, or undefined.

  • getBlendMode(): number
  • getCenterX(): number
  • getCenterXInScene(): number
  • getCenterY(): number
  • getCenterYInScene(): number
  • getColor(): string
  • getDirectionOrAngle(): number
  • getDistanceToPosition(targetX: number, targetY: number): number
  • getDrawableX(): number
  • getDrawableY(): number
  • getHeight(): number
  • getHitBoxesAround(left: number, top: number, right: number, bottom: number): Iterable<Polygon>
  • 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.

  • getLayer(): string
  • getName(): string
  • getNameId(): number
  • getNameIdentifier(name: string): number
  • 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.

    static

    Parameters

    • name: string

    Returns number

  • getOpacity(): number
  • getPointPosition(name: string): [x: number, y: number]
  • Get the positions on X and Y axis on the scene of the given point.

    Parameters

    • name: string

      The point name

    Returns [x: number, y: number]

    An array of the position on X and Y axis on the scene of the given point.

  • getPointX(name: string): number
  • Get the position on X axis on the scene of the given point.

    Parameters

    • name: string

      The point name

    Returns number

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

  • getPointY(name: string): number
  • Get the position on Y axis on the scene of the given point.

    Parameters

    • name: string

      The point name

    Returns number

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

  • getRendererEffects(): Record<string, Filter>
  • getRendererObject(): Sprite
  • getScale(): number
  • Get the scale of the object (or the geometric mean of the X and Y scale in case they are different).

    Returns number

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

  • getScaleMean(): number
  • Get the scale of the object (or the arithmetic mean of the X and Y scale in case they are different).

    deprecated

    Use getScale instead.

    Returns number

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

  • getScaleX(): number
  • getScaleY(): number
  • getSqDistanceToPosition(targetX: number, targetY: number): number
  • getTimerElapsedTimeInSeconds(timerName: string): number
  • Get a timer elapsed time.

    This is used by expressions to return 0 when a timer doesn't exist because numeric expressions must always return a number.

    Parameters

    • timerName: string

      The timer name.

    Returns number

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

  • getTimerElapsedTimeInSecondsOrNaN(timerName: string): number
  • 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 number

    The object identifier

  • getVariableChildCount(variable: Variable): number
  • getVariableNumber(variable: Variable): number
  • getVariableString(variable: Variable): string
  • getVisibilityAABB(): null | 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 null | AABB

    The bounding box or null.

  • getWidth(): number
  • getX(): number
  • getXFromAngleAndDistance(angle: number, distance: number): number
  • 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

    • angle: number

      The angle, in degrees.

    • distance: number

      The distance from the object, in pixels

    Returns number

  • getY(): number
  • getYFromAngleAndDistance(angle: number, distance: number): number
  • 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

    • angle: number

      The angle, in degrees.

    • distance: number

      The distance from the object, in pixels

    Returns number

  • getZOrder(): number
  • hasAnimationEnded(): boolean
  • hasAnimationEnded2(): boolean
  • Return true if animation has ended. The animation had ended if:

    • it's not configured as a loop;
    • the current frame is the last frame;
    • the last frame has been displayed long enough.
    deprecated

    Use hasAnimationEnded instead.

    Returns boolean

  • hasAnimationEndedLegacy(): boolean
  • deprecated

    Return true if animation has ended. Prefer using hasAnimationEnded2. This method returns true as soon as the animation enters the last frame, not at the end of the last frame.

    Returns boolean

  • hasBehavior(name: string): boolean
  • hasEffect(name: string): boolean
  • hasNoForces(): boolean
  • hasVariable(name: string): boolean
  • hide(enable: boolean): void
  • insideObject(x: number, y: number): boolean
  • 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

  • invalidateHitboxes(): void
  • isAnimationPaused(): boolean
  • isCollidingWithPoint(pointX: number, pointY: number): boolean
  • isCurrentAnimationName(name: string): boolean
  • isEffectEnabled(name: string): boolean
  • isFlippedX(): boolean
  • isFlippedY(): boolean
  • isHidden(): boolean
  • isIncludedInParentCollisionMask(): boolean
  • isOnLayer(layer: string): boolean
  • isTotalForceAngleAround(angle: number, toleranceInDegrees: number): boolean
  • Return true if the angle of the total force applied on the object is in a given range.

    Parameters

    • angle: number

      The angle to be tested.

    • toleranceInDegrees: number

      The maximum distance from the given angle.

    Returns boolean

    true if the difference between the force angle the given angle is less or equals the toleranceInDegrees.

  • isVisible(): boolean
  • 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 boolean

    true if the object is not hidden.

  • notifyBehaviorsObjectHotReloaded(): void
  • onCreated(): void
  • 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

  • onDestroyed(): void
  • pauseAnimation(): void
  • pauseTimer(timerName: string): void
  • playAnimation(): void
  • putAround(x: number, y: number, distance: number, angleInDegrees: number): 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

  • putAroundObject(obj: null | RuntimeObject, distance: number, angleInDegrees: number): void
  • 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

    • obj: null | RuntimeObject

      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.

    Returns void

  • raycastTest(x: number, y: number, endX: number, endY: number, closest: boolean): RaycastTestResult
  • Parameters

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

    A raycast result with the contact points and distances

  • registerDestroyCallback(callback: () => void): void
  • 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 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

    Returns void

  • removeBehavior(name: string): boolean
  • 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.

  • removeEffect(effectName: string): boolean
  • removeTimer(timerName: string): void
  • resetTimer(timerName: string): void
  • resumeAnimation(): void
  • rotateTowardPosition(x: number, y: number, speed: number, scene: RuntimeScene): void
  • separateFromObjects(objects: RuntimeObject[], ignoreTouchingEdges: boolean): boolean
  • Separate the object from others objects, using their hitboxes.

    Parameters

    • objects: RuntimeObject[]

      Objects

    • ignoreTouchingEdges: boolean

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

    Returns boolean

    true if the object was moved

  • separateFromObjectsList(objectsLists: ObjectsLists, ignoreTouchingEdges: boolean): boolean
  • Separate the object from others objects, using their hitboxes.

    Parameters

    • objectsLists: ObjectsLists

      Tables of objects

    • ignoreTouchingEdges: boolean

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

    Returns boolean

    true if the object was moved

  • separateObjectsWithForces(objectsLists: ObjectsLists): void
  • separateObjectsWithoutForces(objectsLists: ObjectsLists): void
  • setAngle(angle: number): void
  • setAnimation(newAnimation: number): void
  • Change the animation being played.

    deprecated

    Use setAnimationIndex instead

    Parameters

    • newAnimation: number

      The index of the new animation to be played

    Returns void

  • setAnimationElapsedTime(time: number): void
  • setAnimationFrame(newFrame: number): void
  • setAnimationIndex(newAnimation: number): void
  • setAnimationName(newAnimationName: string): void
  • setAnimationSpeedScale(ratio: number): void
  • setBlendMode(newMode: any): void
  • setCenterPositionInScene(x: number, y: number): void
  • setCenterXInScene(x: number): void
  • setCenterYInScene(y: number): void
  • setColor(rgbOrHexColor: string): void
  • Change the tint of the sprite object.

    Parameters

    • rgbOrHexColor: string

      The color as a string, in RGB format ("128;200;255") or Hex format.

    Returns void

  • setDirectionOrAngle(newValue: number): void
  • setEffectBooleanParameter(name: string, parameterName: string, value: boolean): boolean
  • setEffectDoubleParameter(name: string, parameterName: string, value: number): boolean
  • setEffectStringParameter(name: string, parameterName: string, value: string): boolean
  • setHeight(newHeight: number): void
  • setIncludedInParentCollisionMask(isIncluded: boolean): void
  • setLayer(layer: string): void
  • setOpacity(opacity: number): void
  • setPosition(x: number, y: number): void
  • setScale(newScale: number): void
  • setScaleX(newScale: number): void
  • setScaleY(newScale: number): void
  • setSize(newWidth: number, newHeight: number): void
  • setVariableNumber(variable: Variable, newValue: number): void
  • setVariableString(variable: Variable, newValue: string): void
  • setWidth(newWidth: number): void
  • setX(x: number): void
  • setY(y: number): void
  • setZOrder(z: number): void
  • timerElapsedTime(timerName: string, timeInSeconds: number): boolean
  • Compare a timer elapsed time. If the timer does not exist, it is created.

    deprecated

    prefer using getTimerElapsedTimeInSecondsOrNaN.

    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.

  • timerPaused(timerName: string): boolean
  • unpauseTimer(timerName: string): void
  • unregisterDestroyCallback(callback: () => void): void
  • updateAABB(): void
  • 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

  • updateAllEffectParameters(effectData: EffectData): boolean
  • updateForces(elapsedTime: number): void
  • updateHitBoxes(): void
  • updateTimers(elapsedTime: number): void

Properties

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

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

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

Type declaration

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

      Parameters

      Returns number

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

Type declaration

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

      Parameters

      Returns number

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

Type declaration

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

      Parameters

      Returns string

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

Type declaration

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

      Parameters

      Returns string

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

Type declaration

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

      Parameters

      Returns number

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

Type declaration

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

      Parameters

      Returns number

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

Type declaration

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

      Parameters

      Returns string

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

Type declaration

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

      Parameters

      Returns string

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

Type declaration

    • (targetX: number, targetY: number): number
    • Get the squared distance, in pixels, between the center of this object and a position.

      Parameters

      • targetX: number

        Target X position

      • targetY: number

        Target Y position

      Returns number

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

Type declaration

    • (variable: Variable, compareWith: boolean): boolean
    • 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: Variable) => number = RuntimeObject.getVariableChildCount

Type declaration

    • Get the number of children from a variable

      static

      Parameters

      • variable: Variable

        The variable to be accessed

      Returns number

      The number of children

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

Type declaration

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

      static

      Parameters

      • variable: Variable

        The variable to be accessed

      Returns number

      The value of the specified variable

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

Type declaration

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

      static

      Parameters

      • variable: Variable

        The variable to be accessed

      Returns string

      The string of the specified variable

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.

opacity: number = 255
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) => Variable = RuntimeObject.returnVariable

Type declaration

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

      static

      Parameters

      • variable: Variable

        The variable to be accessed

      Returns Variable

      The specified variable

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

Type declaration

    • (variable: Variable, newValue: boolean): void
    • 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: Variable, newValue: number) => void = RuntimeObject.setVariableNumber

Type declaration

    • (variable: Variable, newValue: number): 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: Variable, newValue: string) => void = RuntimeObject.setVariableString

Type declaration

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

      Parameters

      • variable: Variable

        The variable to be changed

      • newValue: string

        The value to be set

      Returns void

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

Type declaration

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

      see

      {gdjs.evtTools.common.toggleVariableBoolean}

      Parameters

      Returns void

type: string
valuePush: (array: Variable, value: string | number | boolean) => void = RuntimeObject.valuePush

Type declaration

    • (array: Variable, value: string | number | boolean): void
    • This shortcut function is needed for events code generation.

      Parameters

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

      Returns void

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

Type declaration

    • (variable: Variable, childName: string): boolean
    • static

      Parameters

      • variable: Variable

        The variable to be tested

      • childName: string

        The name of the child

      Returns boolean

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

Type declaration

    • static

      Parameters

      • variable: Variable

        The variable to be cleared

      Returns void

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

Type declaration

    • This shortcut function is needed for events code generation.

      Parameters

      Returns void

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

Type declaration

    • This shortcut function is needed for events code generation.

      Parameters

      Returns void

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

Type declaration

    • (variable: Variable, childName: string): void
    • static

      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: Variable, compareWith: boolean) => boolean = ...

Type declaration

    • (variable: Variable, compareWith: boolean): boolean
    • Shortcut to compare the value of a variable considered as a boolean. This shortcut function is needed for events code generation.

      Parameters

      Returns boolean

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

Type declaration

    • (variable: Variable, newValue: boolean): void
    • Shortcut to set the value of a variable considered as a boolean. This shortcut function is needed for events code generation.

      Parameters

      Returns void

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

Type declaration

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

      see

      {gdjs.evtTools.common.toggleVariableBoolean}

      Parameters

      Returns void

valuePush: (array: Variable, value: string | number | boolean) => void = ...

Type declaration

    • (array: Variable, value: string | number | boolean): void
    • This shortcut function is needed for events code generation.

      Parameters

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

      Returns void

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

Type declaration

    • This shortcut function is needed for events code generation.

      Parameters

      Returns void

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

Type declaration

    • This shortcut function is needed for events code generation.

      Parameters

      Returns void

Constructors

Generated using TypeDoc