Skip to main content

GraphicsComponent

Component to manage drawings, using with the position component

Hierarchy

Index

Constructors

constructor

Properties

publiccopyGraphics

copyGraphics: boolean = false

If set to true graphics added to the component will be copied. This can effect performance, but is useful if you don't want changes to a graphic to effect all the places it is used.

optionalreadonlydependencies

dependencies?: ComponentCtor<Component>[]

Optionally list any component types this component depends on If the owner entity does not have these components, new components will be added to the entity

Only components with zero-arg constructors are supported as automatic component dependencies

publicflipHorizontal

flipHorizontal: boolean = false

Flip all graphics horizontally along the y-axis

publicflipVertical

flipVertical: boolean = false

Flip all graphics vertically along the x-axis

publicforceOnScreen

forceOnScreen: boolean = false

Optionally force the graphic onscreen, default false. Not recommend to use for perf reasons, only if you known what you're doing.

publicisVisible

isVisible: boolean = true

Sets or gets wether any drawing should be visible in this component

publicmaterial

material: Material = null

publicoptionalonPostDraw

onPostDraw?: (ctx: ExcaliburGraphicsContext, elapsed: number) => void

Draws after the entity transform has been applied, and after graphics component graphics has been drawn


Type declaration

publicoptionalonPostTransformDraw

onPostTransformDraw?: (ctx: ExcaliburGraphicsContext, elapsed: number) => void

Draws after the entity transform has been applied, and after all graphics component drawing


Type declaration

publicoptionalonPreDraw

onPreDraw?: (ctx: ExcaliburGraphicsContext, elapsed: number) => void

Draws after the entity transform has been applied, but before graphics component graphics have been drawn


Type declaration

publicoptionalonPreTransformDraw

onPreTransformDraw?: (ctx: ExcaliburGraphicsContext, elapsed: number) => void

Draws before the entity transform has been applied before any any graphics component drawing


Type declaration

publicopacity

opacity: number = 1

Sets or gets wither all drawings should have an opacity applied

optionalowner

owner?: Entity<any> = undefined

Current owning Entity, if any, of this component. Null if not added to any Entity

publicshouldAlwaysTick

shouldAlwaysTick: boolean = false

Optionally tick graphics even when offscreen, default false. When true, the current graphic will tick every frame regardless of whether the owning entity is offscreen. This is useful for keeping animations synchronized across your game scene.

Can also be set per-graphic via Animation.shouldAlwaysTick or GraphicsGroup.shouldAlwaysTick.

Accessors

publicanchor

  • Anchor to apply to graphics by default


    Returns Vector

  • Parameters

    Returns void

publicbounds

  • Get world bounds of graphics component


    Returns BoundingBox

publiccolor

  • Sets the color of the actor's current graphic


    Returns Color

  • Parameters

    Returns void

publiccurrent

  • Returns the currently displayed graphic


    Returns Graphic

publiccurrentOptions

publicgraphics

  • get graphics(): {}
  • Returns all graphics associated with this component


    Returns {}

publiclocalBounds

publicoffset

  • Offset to apply to graphics by default


    Returns Vector

  • Parameters

    Returns void

publicoptions

  • get options(): {}
  • Returns all graphics options associated with this component


    Returns {}

publicvisible

  • get visible(): boolean
  • set visible(val: boolean): void
  • Sets or gets wether any drawing should be visible in this component

    @deprecated

    use isVisible


    Returns boolean

  • Sets or gets wether any drawing should be visible in this component

    @deprecated

    use isVisible


    Parameters

    • val: boolean

    Returns void

Methods

publicadd

  • Adds a named graphic to this component, if the name is "default" or not specified, it will be shown by default without needing to call


    Parameters

    Returns Graphic

publicclone

  • Clones any properties on this component, if that property value has a clone() method it will be called


    Returns GraphicsComponent

publicdeserialize

  • Custom deserialization NOTE - This only restores the component's settings, it does NOT restore the graphics themselves.


    Parameters

    Returns void

publicgetGraphic

  • Parameters

    • name: string

    Returns Graphic

publicgetNames

  • getNames(): string[]
  • Get registered graphics names


    Returns string[]

publicgetOptions

publichide

  • hide(): void
  • Hide currently shown graphic


    Returns void

optionalonAdd

  • onAdd(owner: Entity<any>): void
  • Optional callback called when a component is added to an entity


    Parameters

    Returns void

optionalonRemove

  • onRemove(previousOwner: Entity<any>): void
  • Optional callback called when a component is removed from an entity


    Parameters

    Returns void

publicrecalculateBounds

  • recalculateBounds(): void
  • Returns void

publicremove

  • remove(name: string): void
  • Removes a registered graphic, if the removed graphic is the current it will switch to the default


    Parameters

    • name: string

    Returns void

publicserialize

  • Custom serialization - stores graphic references instead of graphic data


    Returns GraphicsComponentData

toJSON

  • toJSON(pretty?: boolean): string
  • Parameters

    • pretty: boolean = false

    Returns string

publicuse

  • Use a graphic only, will set the default graphic. Returns the new Graphic

    Optionally override the stored options


    Type parameters

    Parameters

    Returns T