Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Sprite

Hierarchy

  • Sprite
  • Sprite
    • Sprite

Implements

  • InteractiveTarget
  • AccessibleTarget
  • InteractiveTarget
  • AccessibleTarget

Index

Constructors

Properties

Methods

Constructors

constructor

Properties

Protected _anchor

_anchor: ObservablePoint

Protected _bounds

_bounds: Bounds

Protected _boundsID

_boundsID: number

Protected _boundsRect

_boundsRect: Rectangle

Protected _cacheAsBitmap

_cacheAsBitmap: boolean

Protected _cacheData

_cacheData: boolean

Protected Readonly _destroyed

_destroyed: boolean

Protected _enabledFilters

_enabledFilters: Array<Filter<any>> | null

Protected _filters

_filters: Array<Filter<any>> | null

Protected _height

_height: number

Protected _lastBoundsID

_lastBoundsID: number

Protected _localBoundsRect

_localBoundsRect: Rectangle

Protected _mask

_mask: Graphics | Sprite | null

Protected _texture

_texture: Texture

Protected _textureID

_textureID: number

Protected _textureTrimmedID

_textureTrimmedID: number

Protected _tint

_tint: number

Protected _tintRGB

_tintRGB: number

Protected _transformID

_transformID: number

Protected _transformTrimmedID

_transformTrimmedID: number

Protected _width

_width: number

accessible

accessible: boolean

accessibleHint

accessibleHint: string | null

accessibleTitle

accessibleTitle: string | null

alpha

alpha: number

anchor

anchor: ObservablePoint

blendMode

blendMode: number

buttonMode

buttonMode: boolean

cacheAsBitmap

cacheAsBitmap: boolean

Set this to true if you want this display object to be cached as a bitmap. This basically takes a snap shot of the display object as it is at that moment. It can provide a performance benefit for complex static displayObjects. To remove simply set this property to "false"

IMPORTANT GOTCHA - make sure that all your textures are preloaded BEFORE setting this property to true as it will take a snapshot of what is currently there. If the textures have not loaded then they will not appear.

Protected cachedTint

cachedTint: number

children

children: DisplayObject[]

cursor

cursor: string

defaultCursor

defaultCursor: string
deprecated

filterArea

filterArea: Rectangle | null

filters

filters: Array<Filter<any>> | null

height

height: number

hitArea

hitArea: Rectangle | Circle | Ellipse | Polygon | RoundedRectangle | HitArea

interactive

interactive: boolean

interactiveChildren

interactiveChildren: boolean

localTransform

localTransform: Matrix

mask

mask: Graphics | Sprite | null

name

name: string | null

The instance name of the object.

Protected onChildrenChange

onChildrenChange: function

Type declaration

    • (...args: any[]): void
    • Parameters

      • Rest ...args: any[]

      Returns void

parent

parent: Container

pivot

pivot: Point | ObservablePoint

pluginName

pluginName: string

position

position: Point | ObservablePoint

Optional positionX

positionX: undefined | number

Optional positionY

positionY: undefined | number

renderable

renderable: boolean

rotation

rotation: number

scale

scale: Point | ObservablePoint

skew

skew: ObservablePoint

tabIndex

tabIndex: number

texture

texture: Texture

Protected textureDirty

textureDirty: boolean

tint

tint: number

trackedPointers

trackedPointers: object

Type declaration

  • [key: number]: InteractionTrackingData

transform

transform: TransformBase

vertexData

vertexData: Float32Array

Protected vertexTrimmedData

vertexTrimmedData: Float32Array

visible

visible: boolean

width

width: number

worldAlpha

worldAlpha: number

worldTransform

worldTransform: Matrix

worldVisible

worldVisible: boolean

x

x: number

y

y: number

Static EventEmitter

EventEmitter: object

Type declaration

  • constructor: function
    • new __type(): EventEmitter
    • Returns EventEmitter

  • prefixed: string | boolean

Static prefixed

prefixed: string | boolean

Methods

Protected _cacheAsBitmapDestroy

  • _cacheAsBitmapDestroy(options: boolean | any): void

Protected _calculateBounds

  • _calculateBounds(): void

Protected _calculateCachedBounds

  • _calculateCachedBounds(): Rectangle

Protected _destroyCachedDisplayObject

  • _destroyCachedDisplayObject(): void

Protected _getCachedLocalBounds

  • _getCachedLocalBounds(): Rectangle

Protected _initCachedDisplayObject

  • _initCachedDisplayObject(renderer: WebGLRenderer): void

Protected _initCachedDisplayObjectCanvas

  • _initCachedDisplayObjectCanvas(renderer: CanvasRenderer): void

Protected _onTextureUpdate

  • _onTextureUpdate(): void

Protected _recursivePostUpdateTransform

  • _recursivePostUpdateTransform(): void

Protected _renderCachedCanvas

  • _renderCachedCanvas(renderer: CanvasRenderer): void

Protected _renderCachedWebGL

  • _renderCachedWebGL(renderer: WebGLRenderer): void

Protected _renderCanvas

  • _renderCanvas(renderer: CanvasRenderer): void

Protected _renderWebGL

  • _renderWebGL(renderer: WebGLRenderer): void

addChild

  • addChild<T>(...children: T[]): T
  • Type parameters

    • T: DisplayObject

    Parameters

    • Rest ...children: T[]

    Returns T

addChildAt

  • addChildAt<T>(child: T, index: number): T
  • Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown

    Type parameters

    • T: DisplayObject

    Parameters

    • child: T

      The child to add

    • index: number

      The index to place the child in

    Returns T

    The child that was added.

addListener

  • addListener(event: interaction.InteractionEventTypes, fn: function, context?: any): this
  • Parameters

    • event: interaction.InteractionEventTypes
    • fn: function
        • (event: InteractionEvent): void
        • Parameters

          • event: InteractionEvent

          Returns void

    • Optional context: any

    Returns this

calculateBounds

  • calculateBounds(): void

Protected calculateTrimmedVertices

  • calculateTrimmedVertices(): void
  • calculates worldTransform * vertices for a non texture with a trim. store it in vertexTrimmedData This is used to ensure that the true width and height of a trimmed texture is respected

    Returns void

calculateVertices

  • calculateVertices(): void

Protected containerUpdateTransform

  • containerUpdateTransform(): void

containsPoint

  • containsPoint(point: Point): boolean
  • Tests if a point is inside this sprite

    Parameters

    • point: Point

      the point to test

    Returns boolean

    the result of the test

destroy

  • destroy(options?: DestroyOptions | boolean): void
  • Destroys this sprite and optionally its texture and children

    Parameters

    • Optional options: DestroyOptions | boolean

    Returns void

Protected displayObjectUpdateTransform

  • displayObjectUpdateTransform(): void

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Calls each of the listeners registered for a given event.

    Parameters

    • event: string | symbol

      The event name.

    • Rest ...args: any[]

      Arguments that are passed to registered listeners

    Returns boolean

    true if the event had listeners, else false.

eventNames

  • eventNames(): Array<string | symbol>
  • Return an array listing the events for which the emitter has registered listeners.

    Returns Array<string | symbol>

getBounds

  • getBounds(skipUpdate?: undefined | false | true, rect?: Rectangle): Rectangle
  • Retrieves the bounds of the displayObject as a rectangle object.

    Parameters

    • Optional skipUpdate: undefined | false | true

      setting to true will stop the transforms of the scene graph from being updated. This means the calculation returned MAY be out of date BUT will give you a nice performance boost

    • Optional rect: Rectangle

      Optional rectangle to store the result of the bounds calculation

    Returns Rectangle

    the rectangular bounding area

getChildAt

  • getChildAt<T>(index: number): T
  • Returns the child at the specified index

    Type parameters

    • T: DisplayObject

    Parameters

    • index: number

      The index to get the child at

    Returns T

    The child at the given index, if any.

getChildByName

  • getChildByName<T>(name: string): T
  • Returns the display object in the container

    Type parameters

    • T: DisplayObject

    Parameters

    • name: string

      instance name

    Returns T

    The child with the specified name.

getChildIndex

  • getChildIndex(child: DisplayObject): number
  • Returns the index position of a child DisplayObject instance

    Parameters

    • child: DisplayObject

      The DisplayObject instance to identify

    Returns number

    The index position of the child display object to identify

getGlobalPosition

  • getGlobalPosition(point?: Point, skipUpdate?: undefined | false | true): Point
  • Returns the global position of the displayObject. Does not depend on object scale, rotation and pivot.

    Parameters

    • Optional point: Point

      the point to write the global value to. If null a new point will be returned

    • Optional skipUpdate: undefined | false | true

      setting to true will stop the transforms of the scene graph from being updated. This means the calculation returned MAY be out of date BUT will give you a nice performance boost

    Returns Point

    The updated point

getLocalBounds

  • getLocalBounds(): Rectangle
  • Gets the local bounds of the sprite object.

    Returns Rectangle

    The bounds.

listeners

  • listeners(event: string | symbol): Function[]
  • listeners(event: string | symbol, exists: boolean): boolean
  • Return the listeners registered for a given event.

    Parameters

    • event: string | symbol

      The event name.

    Returns Function[]

  • Check if there listeners for a given event. If exists argument is not true lists listeners.

    Parameters

    • event: string | symbol

      The event name.

    • exists: boolean

      Only check if there are listeners.

    Returns boolean

off

  • off(event: "added" | "removed" | string | symbol, fn?: undefined | function, context?: any): this
  • Parameters

    • event: "added" | "removed" | string | symbol
    • Optional fn: undefined | function
    • Optional context: any

    Returns this

on

  • on(event: interaction.InteractionEventTypes | "added" | "removed", fn: function, context?: any): this
  • on(event: string | symbol, fn: function, context?: any): this
  • Parameters

    • event: interaction.InteractionEventTypes | "added" | "removed"
    • fn: function
        • (event: InteractionEvent): void
        • Parameters

          • event: InteractionEvent

          Returns void

    • Optional context: any

    Returns this

  • Parameters

    • event: string | symbol
    • fn: function
        • (...args: any[]): any
        • Parameters

          • Rest ...args: any[]

          Returns any

    • Optional context: any

    Returns this

Protected onAnchorUpdate

  • onAnchorUpdate(): void

once

  • once(event: interaction.InteractionEventTypes | "added" | "removed", fn: function, context?: any): this
  • once(event: string | symbol, fn: function, context?: any): this
  • Parameters

    • event: interaction.InteractionEventTypes | "added" | "removed"
    • fn: function
        • (event: InteractionEvent): void
        • Parameters

          • event: InteractionEvent

          Returns void

    • Optional context: any

    Returns this

  • Parameters

    • event: string | symbol
    • fn: function
        • (...args: any[]): any
        • Parameters

          • Rest ...args: any[]

          Returns any

    • Optional context: any

    Returns this

removeAllListeners

  • removeAllListeners(event?: interaction.InteractionEventTypes): this
  • Parameters

    • Optional event: interaction.InteractionEventTypes

    Returns this

removeChild

  • removeChild<T>(child: DisplayObject): T
  • Type parameters

    • T: DisplayObject

    Parameters

    • child: DisplayObject

    Returns T

removeChildAt

  • removeChildAt<T>(index: number): T
  • Removes a child from the specified index position.

    Type parameters

    • T: DisplayObject

    Parameters

    • index: number

      The index to get the child from

    Returns T

    The child that was removed.

removeChildren

  • removeChildren<T>(beginIndex?: undefined | number, endIndex?: undefined | number): T[]
  • Removes all children from this container that are within the begin and end indexes.

    Type parameters

    • T: DisplayObject

    Parameters

    • Optional beginIndex: undefined | number
    • Optional endIndex: undefined | number

    Returns T[]

    List of removed children

removeListener

  • removeListener(event: interaction.InteractionEventTypes, fn?: undefined | function, context?: any): this
  • Parameters

    • event: interaction.InteractionEventTypes
    • Optional fn: undefined | function
    • Optional context: any

    Returns this

renderAdvancedWebGL

  • renderAdvancedWebGL(renderer: WebGLRenderer): void

renderCanvas

  • renderCanvas(renderer: CanvasRenderer): void
  • Parameters

    • renderer: CanvasRenderer

    Returns void

renderWebGL

  • renderWebGL(renderer: WebGLRenderer): void
  • Parameters

    • renderer: WebGLRenderer

    Returns void

setChildIndex

  • setChildIndex(child: DisplayObject, index: number): void
  • Changes the position of an existing child in the display object container

    Parameters

    • child: DisplayObject

      The child DisplayObject instance for which you want to change the index number

    • index: number

      The resulting index number for the child display object

    Returns void

setMaxListeners

  • setMaxListeners(): this

setParent

  • setParent(container: Container): Container
  • Parameters

    • container: Container

    Returns Container

setTransform

  • setTransform(x?: undefined | number, y?: undefined | number, scaleX?: undefined | number, scaleY?: undefined | number, rotation?: undefined | number, skewX?: undefined | number, skewY?: undefined | number, pivotX?: undefined | number, pivotY?: undefined | number): DisplayObject
  • Convenience function to set the position, scale, skew and pivot at once.

    Parameters

    • Optional x: undefined | number
    • Optional y: undefined | number
    • Optional scaleX: undefined | number
    • Optional scaleY: undefined | number
    • Optional rotation: undefined | number
    • Optional skewX: undefined | number
    • Optional skewY: undefined | number
    • Optional pivotX: undefined | number
    • Optional pivotY: undefined | number

    Returns DisplayObject

    The DisplayObject instance

swapChildren

  • swapChildren(child: DisplayObject, child2: DisplayObject): void
  • Swaps the position of 2 Display Objects within this container.

    Parameters

    • child: DisplayObject

      First display object to swap

    • child2: DisplayObject

      Second display object to swap

    Returns void

toGlobal

  • toGlobal(position: PointLike): Point
  • toGlobal<T>(position: PointLike, point?: T, skipUpdate?: undefined | false | true): T
  • Calculates the global position of the display object

    Parameters

    • position: PointLike

      The world origin to calculate from

    Returns Point

    A point object representing the position of this object

  • Calculates the global position of the display object

    Type parameters

    • T: PointLike

    Parameters

    • position: PointLike

      The world origin to calculate from

    • Optional point: T
    • Optional skipUpdate: undefined | false | true

    Returns T

    A point object representing the position of this object

toLocal

  • toLocal(position: PointLike, from?: DisplayObject): Point
  • toLocal<T>(position: PointLike, from?: DisplayObject, point?: T, skipUpdate?: undefined | false | true): T
  • Parameters

    • position: PointLike
    • Optional from: DisplayObject

    Returns Point

  • Calculates the local position of the display object relative to another point

    Type parameters

    • T: PointLike

    Parameters

    • position: PointLike

      The world origin to calculate from

    • Optional from: DisplayObject
    • Optional point: T
    • Optional skipUpdate: undefined | false | true

    Returns T

    A point object representing the position of this object

updateTransform

  • updateTransform(): void
  • Updates the transform on all children of this container for rendering

    Returns void

Static from

  • from(source: number | string | BaseTexture | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement): Sprite
  • Parameters

    • source: number | string | BaseTexture | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement

    Returns Sprite

Static fromFrame

  • fromFrame(frameId: string): Sprite
  • Parameters

    • frameId: string

    Returns Sprite

Static fromImage

  • fromImage(imageId: string, crossorigin?: undefined | false | true, scaleMode?: undefined | number): Sprite
  • Parameters

    • imageId: string
    • Optional crossorigin: undefined | false | true
    • Optional scaleMode: undefined | number

    Returns Sprite