groups-and-containers

Organize Phaser 4 game objects with Groups and Containers.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Organizing and managing Phaser 4 game objects can become complex when using Groups, Containers, and layers. This Skill guides how to structure scene hierarchies, pool objects, and batch operations to keep code clean and scalable.

Core Features & Use Cases

  • Logical grouping of similar objects with Group for pooling and lifecycle management.
  • Visual nesting and transform inheritance with Container to create composite UI and entity clusters.
  • Layer-based render ordering and batch operations for performance, with guidance on when to use each structure.
  • Object pooling patterns (getFirstDead, killAndHide) to recycle objects efficiently in dynamic scenes.

Quick Start

In a Scene's create() method, create a Group and a Container, then populate and demonstrate object pooling with getFirstDead.

Frequently Asked Questions about groups-and-containers

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

FAQPage Schema
What is the difference between Groups and Containers in Phaser 4?

Groups handle logical grouping of similar game objects for pooling and lifecycle management, while Containers provide visual nesting and transform inheritance to create composite UI and entity clusters.

How do I implement object pooling in Phaser 4 to recycle game objects?

Object pooling in Phaser 4 uses Group methods like getFirstDead and killAndHide to efficiently recycle inactive game objects in dynamic scenes, reducing memory overhead and improving performance.

When should I use Containers instead of Groups for scene management?

Use Containers when you need visual nesting and transform inheritance for composite UI or entity clusters, and use Groups for logical grouping, object pooling, and batch lifecycle management.

How do I batch render order for game objects in a Phaser scene?

Batch render order in Phaser scenes is managed through layer-based structures and Groups, which organize game objects to control draw order and optimize performance during scene rendering.

Can I use object pooling with Container transform inheritance in Phaser 4?

Yes, pooled objects from a Group can be added to a Container, combining object reuse efficiency with visual transform inheritance for complex, scalable scene hierarchies in Phaser 4.

What are the limitations of using Phaser Containers for game object management?

Containers in Phaser incur transform calculation overhead for nested children, making them less performant than Groups for pure logical batching and object pooling when visual nesting is not required.