What's new in Phaser 4.0 to 4.3
A map of the features added since Phaser 3, by release. Each entry names the API and links to the skill with the detail. For code which must change when porting from v3, use v3-to-v4-migration.
Source: changelog/v4/4.0/CHANGELOG-v4.0.0.md, changelog/v4/4.1/, changelog/v4/4.2/, changelog/v4/4.2.1/, changelog/v4/4.3/CHANGELOG-v4.3.0.md, docs/Phaser 4 Rendering Concepts/. Related: phaser4-core, v3-to-v4-migration.
Most new rendering features are WebGL only. obj.filters is null until enableFilters(), which does nothing in Canvas, and Phaser.AUTO can fall back to Canvas (4.3). Guard them as phaser4-core shows.
Quick start: the v4-only objects with no other skill
create ()
{
const { width, height } = this.scale;
// Gradient: a GPU gradient, as a Game Object. config, x, y, width, height.
this.add.gradient({
bands: [ { colorStart: 0x0b1d51, colorEnd: 0xff7e5f } ],
shapeMode: 2, // 0 LINEAR, 1 BILINEAR, 2 RADIAL, 3 CONIC_SYMMETRIC, 4 CONIC_ASYMMETRIC
start: { x: 0.5, y: 0.5 }
}, width / 2, height / 2, width, height);
// Sky (4.3): a vertical gradient in chunky bands, which fills the game and ignores the Camera.
// Colors run top to bottom: a preset name, or an array of colors and [ color, percent ] stops.
const sky = this.add.sky([ 0x1b1446, [ 0xd9455f, 60 ], 0xffd166 ]).setBandHeight(24);
// Stars are drawn by the Sky. addStars returns the stars, not the Sky.
const stars = sky.addStars({ count: 300, speedY: 40 });
// Noise: the factory names are all lower case.
const clouds = this.add.noisesimplex2d({ noiseIterations: 4, noiseSeed: [ 1, 2 ] }, 200, 200, 256, 256);
this.tweens.add({ targets: clouds, noiseFlow: Math.PI * 2, duration: 8000, repeat: -1 });
// SpriteGPULayer: up to millions of quads from one texture in one draw call.
const layer = this.add.spriteGPULayer('stars', 10000); // texture, maximum members
for (let i = 0; i < 10000; i++)
{
layer.addMember({ x: Math.random() * width, y: Math.random() * height, frame: 'star' });
}
}
- The noise objects are
noise,noisecell2d,noisecell3d,noisecell4d,noisesimplex2dandnoisesimplex3d.noiseSeedis an array of integers. AnimatenoiseOffset(an[x, y]array) to scroll, andnoiseFlow(simplex) or the extra axes (noisecell3d,noisecell4d) to evolve the pattern.noiseNormalMap: trueoutputs a normal map for lighting. - The Gradient colors are a
Phaser.Display.ColorRampofColorBands. Callgradient.ramp.encode()after changing them. - Sky: the config, x, y, width, height. The default size is the game, with an origin of 0 and a scroll factor of 0. Presets:
day,dawn,sunset,dusk,night,rainbow(Phaser.GameObjects.Sky.Presets).setColorscan be called every frame.bandHeightis in pixels, and 0 is a smooth gradient. - Sky colors and the Camera:
setGradientHeight(worldHeight, 1)makes the colors cover the world, so the Sky shows the part the Camera'sscrollYis at. Only vertical scroll changes the colors.scrollY,scrollSpeedandrepeatscroll them by hand.scrollBandsmoves the bands, not just the colors. - Sky stars (
SkyStars):count,layers,color/farColor,size/farSize,speedX/speedYin pixels per second (positive is right and down),cameraFactor(default 0.5),key/framefor a texture.is3D: trueflies them out oforiginX,originYatspeedZ. Seesrc/gameobjects/sky/. - Gradient, Sky and the Noise objects extend
Shader. See custom-rendering. - SpriteGPULayer: fill it once. Adding, editing or removing members rewrites the GPU buffer, which is expensive. Members can animate on the GPU (
x,y,rotation,scaleX,scaleY,alphaandtintBlendtake an animation config). It hassetLighting. Seesrc/gameobjects/spritegpulayer/.
4.0: the new renderer
| Feature | API | Skill |
|---|---|---|
| Render nodes replace pipelines | setRenderNodeRole, render.renderNodes config, addRenderStep |
custom-rendering |
| Filters replace preFX, postFX and FX | enableFilters(), filters.internal, filters.external |
filters-and-postfx |
| The Mask filter replaces BitmapMask | filters.internal.addMask(), Phaser.Actions.AddMaskShape |
masks-and-stencils |
| Effect Actions | Phaser.Actions.AddEffectBloom, AddEffectShine, FitToRegion |
filters-and-postfx, actions-and-utilities |
| Lighting component | setLighting(true), setSelfShadow(), lights have z |
lighting |
| Tint modes | setTintMode(Phaser.TintModes.FILL) and others |
game-object-components |
| Vertex rounding | vertexRoundMode, roundPixels defaults to false, smoothPixelArt |
phaser4-core, scale-and-responsive |
| CaptureFrame | this.add.captureFrame(key): copies what's drawn so far to a texture |
filters-and-postfx |
| Gradient, Noise | this.add.gradient, this.add.noise and the other five |
Quick start above |
| SpriteGPULayer | this.add.spriteGPULayer(texture, size) |
Quick start above |
| TilemapGPULayer | map.createLayer(id, tileset, x, y, true): one quad, one tileset, orthogonal maps |
tilemaps |
| Stamp | this.add.stamp(x, y, texture, frame): a quad which ignores the Camera, for Dynamic Textures |
render-textures |
| Dynamic Texture changes | render() runs the queued draws; preserve, callback, capture; Render Texture renderMode |
render-textures |
| TileSprite | Uses atlas frames; tileRotation |
sprites-and-images |
| NineSlice | tileX, tileY arguments tile the edges |
sprites-and-images |
| Compact texture atlas | this.load.atlasPCT(key, url): a small text atlas format |
loading-assets |
| Hash noise in JS | Phaser.Math.Hash, HashCell, HashSimplex |
geometry-and-math |
| Color ramps | Phaser.Display.ColorBand, ColorRamp; Color helpers can write to an existing Color |
geometry-and-math |
| Destroyed flag | gameObject.isDestroyed |
game-object-components |
4.1 (Salusa)
import Phaser from 'phaser'works: the ESM build has a default export.Layeris a true Game Object, so its filters work. See groups-and-containers.render.mipmapRegenerationlets Dynamic Textures rebuild their mipmaps. Filters never use mipmaps.- Filter Controllers have
getPaddingCeil(). Custom render nodes should call it rather thangetPadding().
4.2 (Giedi)
| Feature | API | Skill |
|---|---|---|
| Stencil | this.add.stencil(x, y, children, options): a Container which writes to the stencil buffer, a fast lasting mask |
masks-and-stencils |
| StencilReference | this.add.stencilreference(stencil, options): draws a Stencil again with other settings |
masks-and-stencils |
| CustomContext | this.add.customcontext(x, y, children, callback): a Container which changes the DrawingContext, such as the scissor or stencil test |
masks-and-stencils |
| Alpha strategies | render.alphaStrategy ('keep'), render.stencil (true), render.stencilAlphaStrategy ('dither'); strategies keep, dither, threshold |
masks-and-stencils |
| Mesh2D | this.add.mesh2d(x, y, texture, vertices, indices): textured triangles which batch with sprites. Vertices are x, y, u, v; indices are a, b, c, page. Supports lighting |
src/gameobjects/mesh2d/Mesh2D.js |
| Cone lights | this.lights.addConeLight(...), light.setCone(), setConeRotation, setConeAngles, disableCone |
lighting |
| Second tint | TintModes.MULTIPLY_TWO, setTint2(), tint2TopLeft and the other corners |
game-object-components |
| FPS limit at runtime | this.game.loop.setFPSLimit(30); 0 removes the limit |
game-setup-and-config |
- The filters render step now runs just before the object's own render step, so other render steps can run first.
inTintEffectin the tint shader changed from afloatto avec4. Only custom shaders which read it are affected.- The new
BatchHandlerTrirender node draws triangles;TransformerVertexhassetupMatrixandtransformVertex. - 4.2.1 fixed
stencilInvert, and stencil clearing in framebuffers.
4.3 (Arrakis)
Graphics and Shapes, all in graphics-and-shapes:
- SDF shapes. WebGL draws circles, ellipses, arcs, rounded rectangles, strokes and lines with signed distance fields. They're round and smooth at any zoom, and look different from 4.2.
render.sdfShapes: falsegoes back to triangles. - Joins. Stroked paths now have pointed joins, as in Canvas.
lineJoin('miter','bevel','round') andmiterLimit(default 10) on Graphics,setLineJoinandsetMiterLimiton Shapes. - Gradients.
fillLinearGradient,fillRadialGradient,lineLinearGradientandlineRadialGradienton Graphics, andsetFillLinearGradient,setFillRadialGradient,setStrokeLinearGradientandsetStrokeRadialGradienton Shapes. Any number of stops. Both renderers draw them. - Hard edges.
setHardEdges(true)turns off the smoothed edge, for a crisp mask. - Clean alpha.
setCleanAlpha()on Graphics and Shapes fades the whole object evenly, so overlapping parts don't show through each other. WebGL only, and it costs a framebuffer while alpha is below 1.
Other features:
| Feature | API | Skill |
|---|---|---|
| Two-color tint | TintModes.MULTIPLY_ADD, with setTint2() |
game-object-components |
| Sky and stars | this.add.sky(colors), sky.addStars(config): banded backdrops and starfields |
Quick start above |
| World3D | this.add.world3D(x, y, width, height): a small, fast 3D world in one Game Object, with models built from shapes, 3D lights, a 3D camera, terrain, particles and decals. WebGL only |
world3d |
| WebGL to Canvas fallback | type: Phaser.AUTO falls back to Canvas if the WebGL Renderer can't be created. Phaser.WEBGL still throws |
game-setup-and-config |
| Abort loading | this.load.xhr.signal = controller.signal, or signal in a file's XHR settings |
loading-assets |
| Loader prefix in config | loader: { prefix: 'LEVEL1.' } |
loading-assets |
| TilemapGPULayer rotation | Tiles rotated in multiples of 90 degrees | tilemaps |
| Isometric shape queries | getTilesWithinShape on isometric layers |
tilemaps |
| CSS-transformed canvas | Pointer positions are right under a CSS rotate; this.scale.transformXY(pageX, pageY) |
input-keyboard-mouse-touch |
| Arcade wrap | this.physics.world.wrap(object, padding, paddingY) |
physics-arcade |
| Matter fixed rotation | setFixedRotation(false) lets a body turn again |
physics-matter |
| Spatial sound | A Sound which follows an object also tracks its z |
audio-and-sound |
| TypeScript | Event constants have literal types; tile lookups and Structs.Map.get are nullable |
events-system |
4.3 changes which alter how existing code behaves:
- Camera follow
lerpis frame-rate independent: the value is the amount moved per frame at 60 fps. See cameras. - The Loader waits before each retry (100 ms, doubling, up to 5 s), and a file loads from the
baseURLset when it was added. See loading-assets. - A Timeline completes once its Tweens have finished.
TweenChain.removeis nowTweenChain.removeTween. See time-and-timers and tweens. dragendgives the samedragXanddragYasdrag. See input-keyboard-mouse-touch.- Matter
restingThreshdefaults changed, andgravityScaleworks again. See physics-matter. - In Canvas, a Dynamic Texture's
draw(entries, x, y)addsxandyto each object's position, as WebGL does. - Self-shadowing reads
penumbraanddiffuseFlatThresholdthe right way round, andsetSelfShadowaffects only its own object. See lighting. Display.Color.GetColor32returns an unsigned integer.LayerextendsGameObject, solayer instanceof Phaser.Structs.Listisfalse.- Arcade Physics separates some collisions in a different order, and a Group colliding with itself uses the dynamic tree.
