phaserjs/phaser/groups-and-containers
Claude Code and agent skill by phaserjs/phaser
- community
Checking that the SKILL.md file is still in the repository.
Phaser 4 Groups, Containers and Layers: this.add.group (object pools with get, classType, maxSize, runChildUpdate, createMultiple, batch setters), this.add.container (children that move, rotate, scale and fade together, setSize for input, list order) and this.add.layer (render order buckets sorted by depth, with alpha, blend mode and filters). Use when pooling bullets or enemies, spawning many of the same object, building a HUD, a button, a health bar or other composite UI, moving a group of objects as one, or controlling what draws on top. Corrects v3 habits: Group has no setScale (use Phaser.Actions.SetScale), get() reuses a member without activating it, a Container ignores child depth, a Layer can't go in a Container, Layer is a real Game Object. Triggers on: Group, Container, Layer, object pool, bullet pool, get, getFirstDead, killAndHide, runChildUpdate, children, render order, draw order, HUD container.
Install
npx vskill@latest install phaserjs/phaser/groups-and-containersSKILL.md
The same SKILL.md was published earlier as phaserjs/phaser/groups-and-containers.
Groups, Containers and Layers
Three ways to collect Game Objects. A Group is a list with pooling. A Container is a parent with a transform. A Layer is a bucket that sets draw order.
Source: src/gameobjects/group/Group.js, src/gameobjects/group/typedefs/, src/gameobjects/container/Container.js, src/gameobjects/layer/Layer.js, src/actions/. Related: physics-arcade (physics groups), actions-and-utilities, cameras (HUD cameras), input-keyboard-mouse-touch.
Quick start
| Group | Container | Layer | ||
|---|---|---|---|---|
| Drawn | No: its members are drawn by the Scene, one by one | Yes, it draws its children | Yes, it draws its children | |
| Position, rotation, scale | No | Yes, children inherit them | No | |
| Alpha, visible, blend mode | Batch setters on the members | Yes, for all children | Yes, for all children | |
| Child draw order | Not a draw order | List order. Child depth is ignored | Sorted by depth | |
| Object in more than one | Yes | No, by default | No | |
Pooling and runChildUpdate | Yes | No | No | |
| Input | On members | Yes, after setSize | No |
Groups and pools
get(x, y, key, frame, visible)returns the first inactive member, or makes a new one if the Group isn't full, or returnsnull. A reused member only has itsxandyset: it's still inactive and maybe hidden, so always callsetActive(true)andsetVisible(true).runChildUpdate: truecallsupdate(time, delta)on every active member, each frame.classTypedefaults toPhaser.GameObjects.Sprite, and is made withnew classType(scene, x, y, key, frame).defaultKeyanddefaultFrameare used whengetorcreatearen't given a key.getFirstDead(createIfNull, x, y),getFirstAlive(),getFirst(active, createIfNull, ...),getLast(...),countActive(true),getTotalUsed(),getTotalFree(),isFull().kill(obj)sets it inactive.killAndHide(obj)also hides it. Neither removes it from the Group.- For a pool with Arcade bodies use
this.physics.add.group({ classType, maxSize })andenableBody/disableBody, becausekillAndHideleaves the body colliding. See physics-arcade.
Making members
- With no
key, nothing is made.keyalone makes one.repeat: 4makes 5, andquantitysets the number directly. - The same keys work in
group.createMultiple(config), which also takes an array of configs. Others:frame,setRotation,setOrigin,setAlpha,setDepth,setScrollFactor,gridAlign.gridAlignis applied aftersetXYand replaces its positions. All are insrc/gameobjects/group/typedefs/GroupCreateConfig.js. create(x, y, key, frame, visible, active)makes one member and adds it to the Scene.add(obj, addToScene = false)adds an existing one.this.add.group([ a, b, c ])makes a Group of existing objects.remove(obj, removeFromScene = false, destroyChild = false),clear(removeFromScene, destroyChild),destroy(destroyChildren = false). A destroyed member leaves the Group by itself.
Changing every member
setX,setY,setXY,setAlpha,setDepth,setOrigin,setTint,setBlendMode,setVisibleset values.incX,incY,incXY,angle,rotate,scaleX,scaleY,scaleXYadd to them.group.setActive()andgroup.setName()set the Group's own properties, not the members'. An inactive Group doesn't runrunChildUpdate.getChildren()returns the members as an array. They are stored in a Set, so there's no index.getMatching('active', true)filters them.shuffle()changes the members' order. It did nothing before 4.3.- For anything else, use
Phaser.Actionsongroup.getChildren(). See actions-and-utilities.
Containers
- Children are placed relative to the Container's position, and take its rotation, scale, alpha and visibility. Containers nest.
addtakes the child off the Scene's display list.remove(child, destroyChild = false)puts it back. Destroying a Container destroys its children.- A Container has no size until
setSize(w, h), which it needs forsetInteractive(). The hit area is centred on the Container'sxandy. getAt(i),getByName(name),getAll(prop, value),count(prop, value),getIndex(child),exists(child),length,each(fn),iterate(fn).eachanditeratepass only the child, not its index.pointToContainer(worldPoint)converts a world point into the Container's local space.- A child can be in one Container at a time. Adding it to another moves it, unless
setExclusive(false). - A Layer can't go in a Container:
addthrows. A Container can go in a Layer.
Draw order in a Container
Children draw in list order, first to last. A child's depth does nothing until you sort:
Or move children directly: bringToTop(child), sendToBack(child), moveUp(child), moveDown(child), moveAbove(child, other), moveBelow(child, other), moveTo(child, index), or child.setToTop().
HUD in a Container
hud.setScrollFactor(0) keeps a Container still on screen. Children which take input need their own scroll factor too, as hit tests use it:
hud.setScrollFactor(0, 0, true) is meant to do both, but in 4.3 it misses children whose scroll factor was never set. A HUD on a zooming camera also needs its own camera: see cameras.
Physics in a Container
An Arcade body on a child of a Container works while the Container isn't rotated or scaled. Otherwise put the body on the Container itself: container.setSize(w, h), then this.physics.add.existing(container).
Fixed in 4.3
- A Container with filters and a scroll factor other than 1, such as a HUD, drew its filtered children in the wrong place when the camera scrolled.
- A DOMElement in a rotated Container rotated around the wrong point, and a DOMElement with an origin drifted when the camera was zoomed.
- A Container nested in another Container could take the blend mode of a sibling.
Layers
A Layer sorts its children by depth, like the Scene, and draws them as one unit. Use it to keep groups of objects above or below each other, whatever order they're made in.
- Layers draw in the Scene's order: by depth, then by the order they were added. A child's depth only orders it within its Layer.
- A Layer has alpha, blend mode, depth, visibility and a Canvas mask. It has no position, scale, rotation, scroll factor, input or physics.
layer.enableFilters()(WebGL only) applies filters to the whole Layer. See filters-and-postfx.- Layers nest, and can hold Containers.
camera.ignore(layer)hides the Layer and everything added to it later. That makes Layers the easy way to split a HUD from the world across two cameras.- Since 4.3, a Layer extends
GameObject:layer instanceof Phaser.GameObjects.GameObjectistrue, andlayer instanceof Phaser.Structs.Listisfalse, though it still has the List methods. - Destroying a Layer destroys its children.
Gotchas
- A Group isn't drawn and has no position. Changing a Group's
xmoves nothing. Use a Container, or the batch setters. - Reused pool members aren't active.
get()only setsxandyon a member it reuses. - Members of a Container or Layer aren't on the Scene's display list.
this.children.getChildren()doesn't list them. - Containers cost more than Layers. Each child's transform is combined with the Container's every frame. Use a Layer when you only need draw order, alpha or visibility.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/groups-and-containers/SKILL.md
Popularity
- Repository stars
- 39,803
- Repository forks
- 7,142
- 7-day trend score
- 53
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Grok Build (Cursor)
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/phaserjs/phaser/groups-and-containers)