groups-and-containers

Organize Phaser 4 game objects using Groups, Containers, and Layers with object pooling.

Updated May 7, 2021
One-click install
npx skills add https://github.com/travispwingo/travispwingo.github.io --skill groups-and-containers-travispwingo
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: groups-and-containers
Source: https://github.com/travispwingo/travispwingo.github.io/tree/main/mario/docs/skills/groups-and-containers
Command: npx skills add https://github.com/travispwingo/travispwingo.github.io --skill groups-and-containers-travispwingo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Phaser 4 developers often struggle to choose between Groups, Containers, and Layers when organizing game objects, and frequently misuse them—causing broken transforms, failed physics, or wasted memory from destroyed-and-recreated objects. ## Core Features & Use Cases - Decision Guidance: Clear comparison tables and rules for choosing Group (logical collection/pooling), Container (nested transforms), or Layer (render ordering). - Object Pooling Patterns: Complete getFirstDead, killAndHide, and maxSize workflows for reusable bullets, enemies, and particles. - Nested Transform & Batch Operations: Container hierarchies for HUDs and composite UI, plus Group batch methods like setXY stepping and createMultiple grid layouts. - Use Case: Build a bullet system with a pooled Group of maxSize 30, a camera-pinned HUD Container with health bar children, and background/entity/UI Layers for render ordering. ## Quick Start Ask the AI to create a Phaser 4 object pool for bullets using a Group with getFirstDead, and a Container-based HUD that follows the camera.

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 Group and Container in Phaser?▼

A Group is a logical collection not on the display list, supporting object pooling with getFirstDead and killAndHide. A Container is a display-list GameObject whose position, rotation, scale, and alpha are inherited by its children, but it has per-child matrix overhead.

How do I implement object pooling in Phaser 4?▼

Create a Group with classType and maxSize, then call group.get(x, y) or getFirstDead(true) to reuse inactive members. Deactivate objects with killAndHide instead of destroying them so they stay available for reuse.

When should I use a Layer instead of a Container in Phaser?▼

Use a Layer when you only need render-order bucketing and shared alpha, blend mode, or mask without position, rotation, or scale. Layers are lighter than Containers and cannot be nested inside Containers.

Why are physics bodies offset when objects are inside a Phaser Container?▼

Physics bodies on Container children become offset when the Container is not positioned at (0,0), because Arcade Physics does not account for the Container's transform. Avoid putting physics-enabled objects inside Containers.

How do I make a Phaser Container receive input events?▼

Containers have no implicit size, so call container.setSize(width, height) before setInteractive() to define a hit area. Without setSize, pointer events on the Container will not fire.