sprites-and-images

Create and manipulate Sprite and Image objects in Phaser 4.

40.1k|7.2k|Updated Apr 12, 2013
One-click install
npx skills add https://github.com/phaserjs/phaser --skill sprites-and-images-phaserjs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sprites-and-images
Source: https://github.com/phaserjs/phaser/tree/main/skills/sprites-and-images
Command: npx skills add https://github.com/phaserjs/phaser --skill sprites-and-images-phaserjs

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill guides developers on creating and manipulating Sprite and Image objects in Phaser 4, covering how to use factory methods, textures, frames, and common visual operations.

Core Features & Use Cases

  • Factory-based creation of Sprite and Image objects via this.add.sprite and this.add.image, with texture/frame handling.
  • Shared component-based APIs for position, scale, rotation, tint, alpha, origin, and depth across both Sprite and Image.
  • Texture and frame management via setTexture and setFrame, plus cropping with setCrop and origin adjustments.
  • Depth, visibility, and render order controls to manage scene composition and UI layering.
  • Real-world scenarios include character rendering, UI elements, and decorative textures in typical 2D game scenes.

Quick Start

In a Scene's create() method, add a Sprite or Image and apply common operations like position, scale, tint, and depth.

Frequently Asked Questions about sprites-and-images

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create and manipulate sprites in a Phaser 4 scene?

To create sprites in Phaser 4, use the `this.add.sprite` factory method within a Scene's `create()` method. You can then manipulate position, scale, rotation, and tint using shared component APIs.

What is the difference between Sprite and Image objects in Phaser 4?

Both Image and Sprite objects in Phaser 4 support shared components for transforms, tint, and origin. The distinction lies in their factory methods, `this.add.image` and `this.add.sprite`, tailored for different rendering requirements in 2D game scenes.

How do I apply tint and adjust the origin of a game texture in Phaser?

Phaser provides shared component-based APIs to apply tint and adjust the origin of game textures. These operations are available across both Sprite and Image objects for precise visual control.

Can I change the texture and frame of an existing Sprite during gameplay?

Yes, you can change the texture and frame of an existing Sprite or Image during gameplay using the `setTexture` and `setFrame` methods. This allows dynamic visual updates for characters and UI elements.

How do I manage depth and render order for UI elements in Phaser 4?

Manage depth and render order for UI elements in Phaser 4 using built-in visibility and depth controls. This manages scene composition and ensures proper layering of characters and decorative textures.

How do I crop a sprite texture in Phaser 4?

Crop a sprite texture in Phaser 4 using the `setCrop` method. This allows you to display specific portions of a texture, which is useful for dynamic UI elements and decorative texture adjustments.