arcade2d
Class

TilingSprite

graphics/tiling-sprite.ts:55

Extends AbstractGraphics<PixiTilingSprite>

Renders a Texture repeated across a rectangular region attached to a WorldObject — the building block for tiled floors, walls, and scrolling backgrounds.

Where a Sprite draws one copy of a texture, a TilingSprite fills a width x height region by repeating its texture as many times as needed. It builds on AbstractGraphics, so it inherits scene-parenting and the once-per-frame transform sync (position, rotation, and the host's scale).

Region size vs. tile size

Two independent levers, neither of which fights the inherited transform sync:

Scrolling

TilingSprite.setTileOffset shifts the tiling pattern within the region; animate it each tick for a parallax/scrolling background.

Example

// A 2000x2000 floor of a 16px tile drawn at 3x, centred on the object.
const floor = world.createObject();
const tile = new Texture(tileset, { x: 16, y: 16, width: 16, height: 16 });
floor.addComponentFromFactory(
  'floor',
  (host) =>
    new TilingSprite(host, tile, {
      width: 2000,
      height: 2000,
      tileScale: 3,
    }),
);

Constructors

#
constructor(host: WorldObject, texture: Texture, options: TilingSpriteOptions): TilingSprite

Parameters

Properties

#
enabled: boolean

Per-component gate on the three update hooks (onPreUpdate, onUpdate, onPostUpdate). When explicitly false, the engine skips all three for this component during the host's tick — useful for temporarily pausing behaviour (e.g. a freeze powerup) without removing the component and losing its internal state.

Does not gate onAdded or onDestroy; those always fire so a host can never end up with a half-attached component.

readonly #
host: WorldObject

The host this component is attached to. Stored read-only; subclasses access it as this.host directly, or through the tier-appropriate aliases (this.world, this.game) on the per-tier abstract bases.

Accessors

#
alpha: number

Opacity from 0 (transparent) to 1 (opaque).

readonly #
anchor: Point

The anchor point as a fresh Point of per-axis fractions (01). See TilingSpriteOptions.anchor. Use TilingSprite.setAnchor to change it.

readonly #
game: Game

The Game the host's world belongs to. Always non-null — the world's game field is a mandatory construction argument, not an option.

#
height: number

The height of the tiled region in world units. See TilingSprite.width.

readonly #
raw: T

Direct access to the underlying Pixi display object.

Use with care. raw is an intentional escape hatch for cases the arcade2d API doesn't cover — custom shaders, filter chains, advanced blend modes, mask assignment, world-space bounds queries, anything we haven't decided how to model yet. Code that touches raw is coupled to Pixi's public API and may break when:

  • arcade2d upgrades Pixi (including minor versions).
  • Pixi itself ships a breaking change.
  • arcade2d swaps Pixi for a different renderer.

None of those will be treated as breaking changes to arcade2d's own surface. Prefer the typed methods on this component; reach for raw only when no equivalent exists, and isolate the access behind your own helper so the coupling is in one place.

readonly #
texture: Texture

The Texture this tiling sprite repeats.

readonly #
tileOffset: Point

The current tiling-pattern offset as a fresh Point. Returned by value; use TilingSprite.setTileOffset to change it.

readonly #
tileScale: Point

The per-tile scale as a fresh Point. Returned by value; use TilingSprite.setTileScale to change it.

#
tint: number

Multiplicative tint as a 24-bit RGB integer; 0xffffff is untinted.

#
visible: boolean

Whether the tiling sprite is drawn.

#
width: number

The width of the tiled region in world units. Setting it changes how many times the texture repeats horizontally; it does not scale the tiles (use TilingSprite.setTileScale) or fight the host transform.

readonly #
world: World

The World the host WorldObject lives in. Shorthand for this.host.world.

Methods

#
onAdded(): void

Lifecycle hook that is called when the component is added to the host object. Should not be called directly.

Returns

void
#
onDestroy(): void

Lifecycle hook that is called when the host object is destroyed. Should not be called directly.

Returns

void
#
onPostUpdate(): void

Returns

void
#
onUpdate(_update: WorldUpdate, _deps: Record): void

Lifecycle hook for the main update phase. Called once per world tick, after every component's onPreUpdate and before any onPostUpdate.

Parameters

Returns

void
#
setAnchor(x: number, y: number): void

Sets the anchor point — the spot on the region that sits on the host's position — as a fraction of the region's size.

Parameters

  • x number
  • y number

Returns

void
#
setTexture(texture: Texture): void

Swaps the repeated Texture. The previous texture is left intact — lifetime belongs to the owning ImageAsset.

Parameters

Returns

void
#
setTileOffset(x: number, y: number): void

Shifts the tiling pattern within the region — animate this for a scrolling background.

Parameters

  • x number
  • y number

Returns

void
#
setTileScale(x: number, y: number): void

Sets the on-screen scale of each repeated tile, independent of the region size and the host transform.

Parameters

  • x number
  • y number

Returns

void
ESC