Skip to content

Sprite Component

The Sprite Component renders textures and images using PIXI.js. It's the primary visual component for displaying 2D graphics in your game.

Purpose

The Sprite Component handles:

  • Texture rendering from image files
  • Visual transformations (position, scale, rotation)
  • Display properties (alpha, tint, visibility)
  • Anchor point positioning

Properties

Required Properties

PropertyTypeDescription
texture_pathstringPath to the texture/image file

Optional Properties

PropertyTypeDefaultDescription
position{ x: number, y: number }{ x: 0, y: 0 }Position in world coordinates
scale{ x: number, y: number }{ x: 1, y: 1 }Scale multipliers for width/height
rotationnumber0Rotation in radians
alphanumber1Opacity (0 = transparent, 1 = opaque)
tintnumberundefinedColor tint applied to sprite (hex color)
visiblebooleantrueWhether the sprite is visible
anchornumber0.5Anchor point (0 = top-left, 0.5 = center, 1 = bottom-right)

Usage Examples

Basic Sprite

typescript
const spriteData: SpriteComponentData = {
  texture_path: "assets/player.png"
};

Positioned Sprite with Custom Properties

typescript
const spriteData: SpriteComponentData = {
  texture_path: "assets/enemy.png",
  position: { x: 100, y: 50 },
  scale: { x: 2, y: 2 },
  rotation: Math.PI / 4, // 45 degrees
  alpha: 0.8,
  tint: 0xff0000, // Red tint
  anchor: 0 // Top-left anchor
};

Invisible Sprite (for delayed reveal)

typescript
const spriteData: SpriteComponentData = {
  texture_path: "assets/hidden-item.png",
  visible: false
};

Runtime Properties

The created component includes all the above properties plus internal PIXI.js objects:

  • _resource: The texture path string
  • _drawable: The PIXI.js Sprite container

Notes

  • Texture paths are relative to your project's asset directory
  • The component uses PIXI.js Sprite internally for hardware-accelerated rendering
  • Anchor values between 0 and 1 position the sprite relative to its bounds
  • Tint values use hexadecimal color format (e.g., 0xff0000 for red)
  • Rotation is measured in radians (use Math.PI / 180 * degrees to convert from degrees)

Released under the Academic License.