phaserjs/phaser/game-object-components

Claude Code and agent skill by phaserjs/phaser

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

The components shared by Phaser 4 Game Objects, and which Game Object has which: Alpha, BlendMode, CleanAlpha, Depth, Flip, Origin, ScrollFactor, Size, Texture, Crop, Tint, Transform, Visible, Mask, Lighting and the rest. Owns the tint modes table (MULTIPLY, FILL, ADD, SCREEN, OVERLAY, HARD_LIGHT, MULTIPLY_TWO, MULTIPLY_ADD, with setTint2) and the component matrix. Also vertexRoundMode and isDestroyed. Use when tinting or flashing a sprite white, fading, ordering with depth, setting an origin, resizing, cropping, pinning a HUD with scroll factor, or checking whether a Game Object has a method. In v4 setTintFill is gone, setTint doesn't change the mode, and setMask is Canvas only. Triggers on: component, mixin, tint, setTintMode, flash white, alpha, blend mode, depth, origin, scroll factor, crop, cleanAlpha, vertexRoundMode.

Install

npx vskill@latest install phaserjs/phaser/game-object-components

SKILL.md

The same SKILL.md was published earlier as phaserjs/phaser/game-object-components.

Game Object components

The mixins that give Game Objects their shared properties and methods, which Game Object has which, and the tint modes.

Source: src/gameobjects/components/, src/gameobjects/GameObject.js, src/renderer/TintModes.js, src/renderer/webgl/shaders/src/ApplyTint.glsl. Related: sprites-and-images, filters-and-postfx, masks-and-stencils, lighting, custom-rendering.

Quick start

js
const { width, height } = this.scale;
const hero = this.add.sprite(width / 2, height / 2, 'hero');
hero.setOrigin(0.5, 1).setDepth(10).setAlpha(0.8).setScale(2);
hero.setTint(0xff8080); // MULTIPLY is the default mode
// Flash white when hit, then restore
hero.setTint(0xffffff).setTintMode(Phaser.TintModes.FILL);
this.time.delayedCall(100, () => hero.clearTint());
// A HUD element which ignores the Camera scroll
this.add.text(16, 16, 'Score: 0').setScrollFactor(0);
// Per-corner alpha and filters are WebGL only
if (this.renderer.type === Phaser.WEBGL)
{
hero.setAlpha(1, 1, 0, 0);
hero.enableFilters();
hero.filters.internal.addGlow(0xffff00);
}

How components work

  • A component is a plain object of properties and methods. Phaser.Class copies it onto the class prototype through the Mixins array. Getters and setters are copied as accessors.
  • Every Game Object has Filters and RenderSteps, from the GameObject base class. The rest depend on the class: see the matrix.
  • Setters return this, so they chain.
  • renderFlags (default 15) holds four bits: Visible (1), Alpha (2), Transform (4, the scale) and Texture (8). The object isn't drawn, and takes no input, unless all four are set. So visible = false, alpha = 0, a scaleX or scaleY of 0, or a frame with no width or height each turn it off.
  • Phaser.Class.mixin(MyClass, [ Phaser.GameObjects.Components.ElapseTimer ]) adds components to your own ES6 class. It works, but isn't in the TypeScript types.

Component matrix

Every Game Object also has Filters and RenderSteps.

Game ObjectComponents
Image, Sprite, RenderTexture, Stamp, ArcadeImage, ArcadeSprite, MatterImage, MatterSpriteAlpha, BlendMode, Depth, Flip, GetBounds, Lighting, Mask, Origin, RenderNodes, ScrollFactor, Size, TextureCrop, Tint, Transform, Visible. The physics versions add their body components
PathFollowerThe Sprite set, plus PathFollower
TextAlpha, BlendMode, ComputedSize, Crop, Depth, Flip, GetBounds, Lighting, Mask, Origin, RenderNodes, ScrollFactor, Tint, Transform, Visible
BitmapText, DynamicBitmapTextAlpha, BlendMode, Depth, GetBounds, Lighting, Mask, Origin, RenderNodes, ScrollFactor, Texture, Tint, Transform, Visible
TileSpriteAlpha, BlendMode, ComputedSize, Depth, Flip, GetBounds, Lighting, Mask, Origin, RenderNodes, ScrollFactor, Texture, Tint, Transform, Visible
VideoThe TileSprite set, with TextureCrop in place of Texture
NineSliceAlphaSingle, BlendMode, Depth, GetBounds, Mask, Origin, RenderNodes, ScrollFactor, Texture, Transform, Visible. Own tint, tintMode, setTint(color), setTintMode()
GraphicsAlphaSingle, BlendMode, CleanAlpha, Depth, Lighting, Mask, RenderNodes, ScrollFactor, Transform, Visible
Arc, Curve, Ellipse, Grid, IsoBox, IsoTriangle, Line, Polygon, Rectangle, Star, TriangleAlphaSingle, BlendMode, CleanAlpha, Depth, GetBounds, Lighting, Mask, Origin, RenderNodes, ScrollFactor, Transform, Visible
Container, CustomContextAlphaSingle, BlendMode, ComputedSize, Depth, Mask, Transform, Visible
StencilThe Container set, plus StencilModifier
StencilReferenceStencilModifier, Visible
LayerAlphaSingle, BlendMode, Depth, Mask, Visible, and the Structs.List methods
BlitterAlpha, BlendMode, Depth, Lighting, Mask, RenderNodes, ScrollFactor, Size, Texture, Transform, Visible. Each Bob has setTint(color)
ParticleEmitterAlphaSingle, BlendMode, Depth, Lighting, Mask, RenderNodes, ScrollFactor, Texture, Transform, Visible. Own tintMode
RopeAlphaSingle, BlendMode, Depth, Flip, Mask, RenderNodes, ScrollFactor, Size, Texture, Transform, Visible. Own colors, alphas, tintMode
Mesh2DAlphaSingle, BlendMode, ComputedSize, Depth, Flip, GetBounds, Lighting, Origin, RenderNodes, ScrollFactor, TextureCrop, Transform, Visible. Own tint, tint2, tintMode
SpriteGPULayerAlpha, BlendMode, Depth, ElapseTimer, Lighting, RenderNodes, TextureCrop, Visible
TilemapLayer, TilemapGPULayerAlpha, BlendMode, ComputedSize, Depth, ElapseTimer, Flip, GetBounds, Lighting, Mask, Origin, RenderNodes, ScrollFactor, Transform, Visible
Shader, Gradient, Noise, NoiseCell2D/3D/4D, NoiseSimplex2D/3DBlendMode, ComputedSize, Depth, GetBounds, Origin, ScrollFactor, Transform, Visible
ExternAlpha, BlendMode, Depth, Flip, Origin, ScrollFactor, Size, Texture, Tint, Transform, Visible
DOMElementAlphaSingle, BlendMode, Depth, Origin, ScrollFactor, Transform, Visible
PointLightAlphaSingle, BlendMode, Depth, Mask, RenderNodes, ScrollFactor, Transform, Visible
CaptureFrameBlendMode, Depth, RenderNodes, Visible
ZoneDepth, GetBounds, Origin, ScrollFactor, Transform, Visible

Each class lists its mixins in its own file, such as src/gameobjects/sprite/Sprite.js.

Tint

Tint is WebGL only. The tint color and the tint mode are separate: setTint sets colors, setTintMode sets the mode.

ModeValueResult, per pixel
Phaser.TintModes.MULTIPLY0texture * tint. The default
FILL1tint, keeping the texture's alpha. Use it to flash a sprite
ADD2texture + tint
SCREEN41 - (1 - texture) * (1 - tint): lightens
OVERLAY5Darkens dark areas and lightens light ones, by the texture
HARD_LIGHT6Overlay with tint and texture swapped
MULTIPLY_TWO (4.2)7texture * tint + (1 - texture) * tint2: tint colors the light parts, tint2 the dark parts
MULTIPLY_ADD (4.3)8texture * tint + tint2, like a Flash color transform

There's no mode 3. The two-color modes use the secondary tint, tint2.

MemberNotes
setTint(topLeft, topRight, bottomLeft, bottomRight)Default 0xffffff. One argument sets all four corners. Doesn't change the mode
setTint2(topLeft, topRight, bottomLeft, bottomRight)4.2. Default 0x000000. Only the two-color modes use it
setTintMode(mode)A Phaser.TintModes value
tintGets tintTopLeft; setting it sets all four corners
tintTopLeft ... tintBottomRightDefault 0xffffff
tint2TopLeft ... tint2BottomRightDefault 0x000000. There's no tint2 shortcut on the Tint component
tintModeDefault Phaser.TintModes.MULTIPLY
clearTint()Sets the tint to 0xffffff, tint2 to 0x000000 and the mode to MULTIPLY
isTintedtrue if any corner of tint isn't white, any corner of tint2 isn't black, or the mode isn't MULTIPLY
js
// Fire: yellow highlights, dark red shadows
sprite.setTint(0xffff00).setTint2(0x800000).setTintMode(Phaser.TintModes.MULTIPLY_TWO);
// Negative image
sprite.setTint(0x000000).setTint2(0xffffff).setTintMode(Phaser.TintModes.MULTIPLY_TWO);

Game Objects with their own tint API:

  • Mesh2D: tint, tint2, tintMode, setTint(color), setTint2(color), setTintMode(), clearTint(), and isTinted(), a method.
  • NineSlice: setTint(color) and setTintMode(), with no tint2.
  • Tilemaps: each Tile has tint, tint2 and tintMode. TilemapLayer.setTint, setTint2 and setTintMode take a color and a tile area. A TilemapGPULayer can't tint tiles.
  • ParticleEmitter has tintMode; the color comes from the emitter's tint config. Particles have no tint2.
  • Group.setTint() tints every child.

Components with v4 changes or traps

Alpha and AlphaSingle. Alpha has per-corner alpha: setAlpha(topLeft, topRight, bottomLeft, bottomRight), WebGL only. AlphaSingle has one value. A Container's alpha multiplies into its children.

CleanAlpha (4.3, Graphics and Shapes). Normally each fill and stroke gets the object's alpha, so overlaps show darker. setCleanAlpha() draws the object at alpha 1 to a Camera-sized texture, then fades that texture. It calls enableFilters(), so it's WebGL only. It costs a draw call and a full-Camera pass for each object while its alpha is below 1, so use it only where the overlaps show.

js
const ring = this.add.circle(200, 200, 80, 0x3366ff).setStrokeStyle(8, 0xffffff);
if (this.renderer.type === Phaser.WEBGL)
{
ring.setCleanAlpha();
}
ring.setAlpha(0.5);

BlendMode. WebGL draws NORMAL, ADD, MULTIPLY, SCREEN and ERASE. Any other Phaser.BlendModes value draws as NORMAL in WebGL; use the Blend filter for them. Canvas has the full set.

Origin. The default is 0.5, 0.5. Text, BitmapText, DynamicBitmapText and tilemap layers default to 0, 0. Graphics, Container, Layer, Blitter, Rope, SpriteGPULayer, CaptureFrame and PointLight have no Origin: they draw from their x and y.

Size and ComputedSize. setSize() changes the size used for bounds, input and physics, not what is drawn. setDisplaySize() and displayWidth / displayHeight change the scale. Size also has setSizeToFrame(). ComputedSize has no frame.

Texture, TextureCrop and Crop. setCrop(x, y, width, height), or setCrop() to clear it, is on objects with TextureCrop, and on Text through Crop. TileSprite, BitmapText, NineSlice and others have plain Texture, so they can't be cropped.

Depth. setDepth() sorts the display list. setToTop(), setToBack(), setAbove(obj) and setBelow(obj) move the object in its list without changing depth, so they only order objects of the same depth.

Transform. z and w aren't draw order; use depth. getWorldTransformMatrix(), getWorldPoint() and getLocalPoint(x, y) include parent Containers.

Mask. Canvas only. In WebGL, setMask() logs a warning and does nothing. See masks-and-stencils.

Lighting. setLighting(true), setSelfShadow(). WebGL only. See lighting.

Filters, RenderSteps and RenderNodes. enableFilters(), then filters.internal / filters.external. See filters-and-postfx. addRenderStep() and setRenderNodeRole() are in custom-rendering.

StencilModifier. The stencil settings of Stencil and StencilReference. See masks-and-stencils.

ElapseTimer. A clock for shader animation on SpriteGPULayer and the tilemap layers: timeElapsed, setTimerPaused(), resetTimer(), setTimerResetPeriod() (default one hour).

PathFollower. See curves-and-paths.

Game Object members

These are on every Game Object, not in a component:

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

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
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/phaserjs/phaser/game-object-components/badge)](https://verified-skill.com/skills/phaserjs/phaser/game-object-components)

Something wrong with this skill or its page? Tell us.