Loading...
Loading...
Use this skill when working with Phaser 4 utility functions, actions, alignment, grid layout, or batch operations on game objects. Triggers on: align, grid layout, actions, set operations on groups of game objects.
npx skill4agent add phaserjs/phaser actions-and-utilitiesPhaser.Actions namespace for batch operations on Game Object arrays, plus Phaser.Utils.Array, Phaser.Utils.Objects, and Phaser.Utils.String helper functions.
// Create 20 sprites and batch-position them in a grid
const sprites = [];
for (let i = 0; i < 20; i++) {
sprites.push(this.add.sprite(0, 0, 'gem'));
}
// Arrange into a 5x4 grid
Phaser.Actions.GridAlign(sprites, {
width: 5,
height: 4,
cellWidth: 64,
cellHeight: 64,
x: 100,
y: 100
});
// Fade alpha from 0 to 1 across all sprites
Phaser.Actions.Spread(sprites, 'alpha', 0, 1);
// Offset each sprite's x by 10, with a step of 2 per item
Phaser.Actions.IncX(sprites, 10, 2);
// Works with Groups too
const group = this.add.group({ key: 'star', repeat: 11 });
Phaser.Actions.PlaceOnCircle(group.getChildren(), new Phaser.Geom.Circle(400, 300, 200));Phaser.Actionsxyalphagroup.getChildren()PropertyValueSet(items, key, value, step, index, direction)items[i][key] = value + (i * step)PropertyValueInc(items, key, value, step, index, direction)items[i][key] += value + (i * step)stepindexdirectionPlaceOnCirclePlaceOnLineRandomRectanglePhaser.Geom.CirclePhaser.Geom.LinePhaser.GameObjects.Circle.geom| Action | Signature | Description |
|---|---|---|
| | Set |
| | Set |
| | Set both |
| | Set |
| | Set blend mode |
| | Set render depth |
| | Set interactive hit area |
| | Set origin point |
| | Set rotation (radians) |
| | Set both scale axes |
| | Set |
| | Set |
| | Set scroll factor |
| | Set horizontal scroll factor |
| | Set vertical scroll factor |
| | Set tint color(s) |
| | Set visibility |
| | Generic: set any named property |
| Action | Signature | Description |
|---|---|---|
| | Add to |
| | Add to |
| | Add to |
| | Add to |
| | Add to |
| | Add to |
| | Add to |
| | Add to both scale axes |
| | Add to |
| | Generic: increment any named property |
| Action | Signature | Description |
|---|---|---|
| | Evenly space on circle perimeter |
| | Evenly space on ellipse perimeter |
| | Evenly space along a line |
| | Evenly space on rectangle perimeter |
| | Evenly space on triangle perimeter |
| | Random positions within a circle |
| | Random positions within an ellipse |
| | Random positions along a line |
| | Random positions within a rectangle |
| | Random positions within a triangle |
| Action | Signature | Description |
|---|---|---|
| | Arrange in grid; config: |
| | Chain-align each item next to the previous one using |
| | Scale/position each GO to fill a rectangle (v4.0.0+). scaleMode: 0=stretch, -1=fit inside, 1=cover outside |
| Action | Signature | Description |
|---|---|---|
| | Linearly distribute a property from |
| | Distribute using Hermite smoothstep interpolation |
| | Distribute using Ken Perlin's smootherstep |
| Action | Signature | Description |
|---|---|---|
| | Rotate all items around a point (radians) |
| | Rotate around a point at a fixed distance |
| | Snake-like: move head to x/y, each item takes position of the previous |
| | Wrap x/y to stay within rectangle bounds |
| Action | Signature | Description |
|---|---|---|
| | Find first item matching all properties in |
| | Find last item matching all properties in |
| | Invoke callback for each item |
| | Randomly reorder the array (Fisher-Yates) |
| | Toggle |
| | Play animation on all items with an |
| Action | Signature | Description |
|---|---|---|
| | Add Bloom filter effect to a Camera or GO. Returns |
| | Add Shine filter effect |
| | Apply a shape-based mask (circle, square, rectangle, ellipse) with optional blur |
Phaser.Utils.Array| Function | Signature | Description |
|---|---|---|
| | Add item(s) if not already present; optional size limit |
| | Insert item(s) at index |
| | Move item to end of array |
| | Count items where property equals value |
| | Iterate with callback; passes item + extra args |
| | Iterate a slice with callback |
| | Binary-search style closest match in sorted array |
| | Flatten nested arrays into a single array |
| | Filter items matching property/value |
| | First item matching property/value |
| | Return a random element |
| | Move item2 directly above item1 |
| | Move item2 directly below item1 |
| | Move item one position toward index 0 |
| | Move item to specific index |
| | Move item one position toward end |
| | Generate |
| | Generate range with custom step size |
| | Partial sort: kth smallest element in-place |
| | Generate array from range config |
| | Remove item(s) from array |
| | Remove item at index |
| | Remove items in range |
| | Remove and return a random element |
| | Swap one item for another |
| | Shift elements left; last wraps to front |
| | Shift elements right; first wraps to end |
| | Validate index range is within bounds |
| | Move item to index 0 |
| | Set a property on all items in range |
| | Fisher-Yates shuffle; modifies in-place |
| | Sort strings by embedded numeric values |
| | Fast single-element splice |
| | Guaranteed stable sort (merge sort fallback for engines without native stable sort) |
| | Swap two items in-place |
Phaser.Utils.Array.MatrixPhaser.Utils.Objects| Function | Signature | Description |
|---|---|---|
| | Shallow clone of object |
| | Recursive deep copy of object or array |
| | jQuery-style extend; copies properties from sources to target |
| | Like |
| | Top-level-only property lookup; no dot-path support. Faster than |
| | Get value clamped between min and max |
| | Dot-path property lookup (e.g. |
| | True if source has ALL listed keys |
| | True if source has ANY listed key |
| | True if source has the key |
| | True if obj is a plain |
| | Merge obj2 into a clone of obj1 |
| | Merge obj1 into a clone of obj2 |
| | Return new object with only the specified keys |
| | Set a dot-path property value |
Phaser.Utils.String| Function | Signature | Description |
|---|---|---|
| | Replace |
| | Pad string to length. dir: 1=left, 2=right, default=both |
| | Remove character at index |
| | Reverse the string |
| | Capitalize first character |
| | Generate RFC4122 v4 UUID string |
const enemies = this.add.group({ key: 'enemy', repeat: 9 });
// Position all children in a grid
Phaser.Actions.GridAlign(enemies.getChildren(), {
width: 5, height: 2,
cellWidth: 80, cellHeight: 80,
x: 100, y: 50
});
// Fan out alpha across all enemies
Phaser.Actions.Spread(enemies.getChildren(), 'alpha', 0.3, 1);// Place sprites starting at x=100, each one 50px further right
Phaser.Actions.SetX(sprites, 100, 50);
// Result: items[0].x=100, items[1].x=150, items[2].x=200, ...
// Increment rotation with increasing step
Phaser.Actions.Rotate(sprites, 0.1, 0.05);
// Result: items[0].rotation += 0.1, items[1].rotation += 0.15, items[2].rotation += 0.2, ...const bounds = new Phaser.Geom.Rectangle(0, 0, 800, 600);
// Random scatter
Phaser.Actions.RandomRectangle(sprites, bounds);
// Keep wrapped in bounds during update
Phaser.Actions.WrapInRectangle(sprites, bounds);// Deep property access with fallback
const width = Phaser.Utils.Objects.GetValue(config, 'render.screen.width', 800);
// Fast top-level lookup (no dot-path, better performance)
const speed = Phaser.Utils.Objects.GetFastValue(config, 'speed', 100);// Generate frame key strings
const keys = Phaser.Utils.Array.NumberArray(1, 10, 'frame_', '.png');
// Result: ['frame_1.png', 'frame_2.png', ..., 'frame_10.png']group.getChildren()Phaser.GeomPhaser.GameObjects.Circlecircle.geomSetXYyxyundefinednull0Spread(min + max) / 2minstepvalue + 0*stepvalue + 1*stepStableSortArray.sortShuffleGetValueGetFastValueGetFastValueAddEffectBloomAddEffectShineAddMaskShape| Area | Path |
|---|---|
| All Actions | |
| Actions index | |
| Core set/inc helpers | |
| GridAlign config typedef | |
| Array utilities | |
| Array matrix utils | |
| Object utilities | |
| String utilities | |