Releases: phaserjs/phaser
Phaser v3.25.0 Beta 0
WebGL Multi-Texture Rendering
The Texture Tint Pipeline has had its core flow rewritten to eliminate the need for constantly creating batch
objects. Instead, it now supports the new multi-texture shader, vastly increasing rendering performance, especially on drawcall-bound systems.
All of the internal functions, such as batchQuad
and batchSprite
have been updated to use the new method of texture setting. The method signatures all remain the same, unless indicated below.
Config.render.maxTextures
is a new game config setting that allows you to control how many texture units will be used in WebGL.WebGL.Utils.checkShaderMax
is a new function, used internally by the renderer, to determine the maximum number of texture units the GPU + browser supports.- The property
WebGLRenderer.currentActiveTextureUnit
has been renamed tocurrentActiveTexture
. WebGLRenderer.startActiveTexture
is a new read-only property contains the current starting active texture unit.WebGLRenderer.maxTextures
is a new read-only property that contains the maximum number of texture units WebGL can use.WebGLRenderer.textureIndexes
is a new read-only array that contains all of the available WebGL texture units.WebGLRenderer.tempTextures
is a new read-only array that contains temporary WebGL textures.- The
WebGLRenderer.currentTextures
property has been removed, as it's no longer used. TextureSource.glIndex
is a new property that holds the currently assigned texture unit for the Texture Source.TextureSource.glIndexCounter
is a new property that holds the time the index was assigned to the Texture Source.WebGLRenderer.currentTextures
has been removed, as it's no longer used internally.WebGLRenderer.setBlankTexture
no longer has aforce
parameter, as it's set by default.- The Mesh Game Object WebGL Renderer function has been updated to support multi-texture units.
- The Blitter Game Object WebGL Renderer function has been updated to support multi-texture units.
- The Bitmap Text Game Object WebGL Renderer function has been updated to support multi-texture units.
- The Dynamic Bitmap Text Game Object WebGL Renderer function has been updated to support multi-texture units.
- The Particle Emitter Game Object WebGL Renderer function has been updated to support multi-texture units.
- The Texture Tint vertex and fragment shaders have been updated to support the
inTexId
float attribute and dynamic generation. - The Texture Tint Pipeline has a new attribute,
inTexId
which is agl.FLOAT
. TextureTintPipeline.bind
is a new method that sets theuMainSampler
uniform.- The
TextureTintPipeline.requireTextureBatch
method has been removed, as it's no longer required. - The
TextureTintPipeline.pushBatch
method has been removed, as it's no longer required. - The
TextureTintPipeline.maxQuads
property has been removed, as it's no longer required. - The
TextureTintPipeline.batches
property has been removed, as it's no longer required. TextureTintPipeline.flush
has been rewritten to support multi-textures.TextureTintPipeline.flush
no longer creates a sub-array if the batch is full, but instead usesbufferData
for speed.WebGLPipeline.currentUnit
is a new property that holds the most recently assigned texture unit. Treat as read-only.WebGLRenderer.setTextureSource
is a new method, used by pipelines and Game Objects, that will assign a texture unit to the given Texture Source.- The
WebGLRenderer.setTexture2D
method has been updated to use the new texture unit assignment. It no longer takes thetextureUnit
orflush
parameters and these have been removed from its method signature. WebGLRenderer.setTextureZero
is a new method that activates texture zero and binds the given texture to it. Useful for fbo backed game objects.WebGLRenderer.clearTextureZero
is a new method that clears the texture tha was bound to unit zero.WebGLRenderer.textureZero
is a new property that holds the currently bound unit zero texture.WebGLRenderer.normalTexture
is a new property that holds the currently bound normal map (texture unit one).WebGLRenderer.setNormalMap
is a new method that sets the current normal map texture.WebGLRenderer.clearNormalMap
is a new method that clears the current normal map texture.WebGLRenderer.resetTextures
is a new method that flushes the pipeline, resets all textures back to the temporary ones and resets the active texture counter.WebGLPipeline.boot
will now check all of the attributes and store the pointer location within the attribute entry.WebGLPipeline.bind
no longer looks-up and enables every attribute, every frame. Instead it uses the cached pointer location stored in the attribute entry, cutting down on redundant WebGL operations.WebGLRenderer.isNewNormalMap
is a new method that returns a boolean if the given parameters are not currently used.WebGLPipeline.forceZero
is a new property that informs Game Objects if the pipeline requires a zero bound texture unit.WebGLPipeline.setAttribPointers
is a new method that will set the vertex attribute pointers for the pipeline.WebGLRenderer.unbindTextures
is a new method that will activate and then null bind all WebGL textures.
Forward Diffuse Light Pipeline API Changes
This Light2D pipeline, which is responsible for rendering lights under WebGL, has been rewritten to work with the new Texture Tint Pipeline functions. Lots of redundant code has been removed and the following changes and improvements took place:
- The pipeline now works with Game Objects that do not have a normal map. They will be rendered using the new default normal map, which allows for a flat light effect to pass over them and merge with their diffuse map colors.
- Fixed a bug in the way lights were handled that caused Tilemaps to render one tile at a time, causing massive slow down. They're now batched properly, making a combination of lights and tilemaps possible again.
- The Bitmap Text (Static and Dynamic) Game Objects now support rendering with normal maps.
- The TileSprite Game Objects now support rendering with normal maps.
- Mesh and Quad Game Objects now support rendering with normal maps.
- The Graphics Game Objects now support rendering in Light2d. You can even use normal map textures for the texture fills.
- Particle Emitter Game Object now supports rendering in Light2d.
- All Shape Game Objects (Rectangle, IsoBox, Star, Polygon, etc) now support rendering in Light2d.
- The Text Game Object now supports rendering in Light2d, no matter which font, stroke or style it is using.
- Both Static and Dynamic Tilemap Layer Game Objects now support the Light2d pipeline, with or without normal maps.
- The pipeline will no longer look-up and set all of the light uniforms unless the
Light
is dirty. - The pipeline will no longer reset all of the lights unless the quantity of lights has changed.
- The
ForwardDiffuseLightPipeline.defaultNormalMap
property has changed, it's now an object with aglTexture
property that maps to the pipelines default normal map. - The
ForwardDiffuseLightPipeline.boot
method has been changed to now generate a default normal map. - The
ForwardDiffuseLightPipeline.onBind
method has been removed as it's no longer required. - The
ForwardDiffuseLightPipeline.setNormalMap
method has been removed as it's no longer required. ForwardDiffuseLightPipeline.bind
is a new method that handles setting-up the shader uniforms.- The
ForwardDiffuseLightPipeline.batchTexture
method has been rewritten to use the Texture Tint Pipeline function instead. - The
ForwardDiffuseLightPipeline.batchSprite
method has been rewritten to use the Texture Tint Pipeline function instead. ForwardDiffuseLightPipeline.lightCount
is a new property that stores the previous number of lights rendered.ForwardDiffuseLightPipeline.getNormalMap
is a new method that will look-up and return a normal map for the given object.
Lights
Light.dirty
is a new property that controls if the light is dirty, or not, and needs its uniforms updating.Light
has been recoded so that all of its properties are now setters that activate itsdirty
flag.LightsManager.destroy
will now clear thelightPool
array when destroyed, where-as previously it didn't.LightsManager.cull
now takes the viewport height from the renderer instead of the game config (thanks zenwaichi)
WebGL ModelViewProjection API Changes
The ModelViewProjection
object contained a lot of functions that Phaser never used internally. These have now been
moved to external functions, which can be easily excluded from Custom builds to save space.
If you used any of them in your code, please update to the new function names below:
Phaser.Renderer.WebGL.MVP
is a new namespace under which the Model View Projection functions now live.projIdentity
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ProjectIdentity
projPersp
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ProjectPerspective
modelRotateX
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.RotateX
modelRotateY
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.RotateY
modelRotateZ
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.RotateZ
viewLoad
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewLoad
viewRotateX
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewRotateX
viewRotateY
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewRotateY
viewRotateZ
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewRotateZ
viewScale
is now available as a stand-alone function `Phaser.Renderer.WebGL.MVP.View...
Phaser v3.24.1
Version 3.24.1 - Rem - 14th July 2020
- Reverted the PR that added the parent transform to a Static Tilemap Layer as it broke tilemap rendering when the camera was zoomed (thanks @kainage)
- Fixed an error with the use of the Vector2Like type in the
Math.RotateTo
function that caused a TypeScript error on compilation
Version 3.24.0 - Rem - 13th July 2020
Arcade Physics New Features, Updates and Fixes
- When colliding physics groups with the search tree enabled, there was an unnecessary intersection test for each body returned by the search (thanks @samme)
- When doing an overlap collision, there was an unnecessary intersection test for each pair of overlapping bodies (thanks @samme)
- Sprite vs. Static Group collision tests now always use the static tree (thanks @samme)
- Fixed a bug where if you added a static body to a sprite with scale ≠ 1, the body position was incorrect (thanks @samme)
- If you passed in an array of
children
when creating a Physics Group, they didn't receive bodies. Fix #5152 (thanks @samme) - New types allow for better docs / TypeScript defs especially in the Factory functions:
ArcadePhysicsCallback
,GameObjectWithBody
,GameObjectWithDynamicBody
,GameObjectWithStaticBody
,ImageWithDynamicBody
,ImageWithStaticBody
,SpriteWithDynamicBody
andSpriteWithStaticBody
. Fix #4994 (thanks @samme @gnesher) Body.updateFromGameObject
is a new method that extracts the relevant code frompreUpdate
, allowing you to read the body's new position and center immediately, before the next physics step. It also letsrefreshBody
work for dynamic bodies, where previously it would error (thanks @samme)- Momentum exchange wasn't working correctly vs. immovable bodies. The movable body tended to stop. Fix #4770 (thanks @samme)
- The Body mass was decreasing the inertia instead of increasing it. Fix #4770 (thanks @samme)
- The separation vector seemed to be incorrect, causing the slip / slide collisions. The separation is now correct for circle–circle collisions (although not fully for circle–rectangle collisions), part fix #4770 (thanks @samme)
- The Arcade Body delta was incorrectly calculated on bodies created during the
update
step, causing the position to be off. Fix #5204 (thanks @zackexplosion @samme) Arcade.Components.Size.setBodySize
is a new method available on Arcade Physics Game Objects that allows you to set the body size. This replacessetSize
which is now deprecated. Fix #4786 (thanks @wingyplus)
New Features
- The Animation component has a new property
nextAnimsQueue
which allows you to sequence Sprite animations to play in order, i.e:this.mole.anims.play('digging').anims.chain('lifting').anims.chain('looking').anims.chain('lowering');
(thanks @tgroborsch) Group.setActive
is a new method that will set the active state of a Group, just like it does on other Game Objects (thanks @samme)Group.setName
is a new method that will set the name property of a Group, just like it does on other Game Objects (thanks @samme)TWEEN_STOP
is a new event dispatched by a Tween when it stops playback (thanks @samme @RollinSafary)- You can now specify an
onStop
callback when creating a Tween as part of the tween config, which is invoked when a Tween stops playback (thanks @samme @RollinSafary) - Previously, if you created a timeline and passed no tweens in the config, the timeline would be created but all config properties were ignored. Now the timeline's own properties (completeDelay, loop, loopDelay, useFrames, onStart, onUpdate, onLoop, onYoyo, onComplete, etc.) are set from the config properly (thanks @samme)
TextStyle.wordWrapWidth
lets you set the maximum width of a line of text (thanks @mikewesthad)TextStyle.wordWrapCallback
is a custom function that will is responsible for wrapping the text (thanks @mikewesthad)TextStyle.wordWrapCallbackScope
is the scope that will be applied when thewordWrapCallback
is invoked (thanks @mikewesthad)TextStyle.wordWrapUseAdvanced
controls whether or not to use the advanced wrapping algorithm (thanks @mikewesthad)KeyboardPlugin.removeAllKeys
is a new method that allows you to automatically remove all Key instances that the plugin has created, making house-keeping a little easier (thanks @samme)Math.RotateTo
is a new function that will position a point at the given angle and distance (thanks @samme)Display.Bounds.GetBounds
is a new function that will return the un-transformed bounds of the given Game Object as a Rectangle (thanks @samme)
Updates
- The
Pointer.dragStartX/YGlobal
andPointer.dragX/Y
values are now populated from theworldX/Y
, which means using those values directly in Input Drag callbacks will now work when the Camera is zoomed. Fix #4755 (thanks @braindx) - The
browser
field has been added to the Phaserpackage.json
pointing to thedist/phaser.js
umd build (thanks @FredKSchott) - Calling
TimeStep.wake()
while the loop is running will now cause nothing to happen, rather than sleeping and then waking again (thanks @samme) Container.getBounds
will no longer set the temp rect bounds to the first child of the Container by default (which would error if the child had no bounds, like a Graphics object) and instead sets it as it iterates the children (thanks @blopa)File.state
will now be set to theFILE_LOADING
state while loading andFILE_LOADED
after loading (thanks @samme)BaseCamera.cull
now moves some of its calculations outside of the cull loop to speed it up (thanks @samme)SceneManager.createSceneFromInstance
had a small refactor to avoid a pointless condition (thanks @samme)
Bug Fixes
- Fixed a TypeError warning when importing JSON objects directly to the
url
argument of any of the Loader filetypes. Fix #5189 (thanks @awweather @samme) - The
NOOP
function was incorrectly imported by the Mouse and Keyboard Manager. Fix #5170 (thanks @samme @gregolai) - When Audio files failed to decode on loading, they would always show 'undefined' as the key in the error log, now they show the actual key (thanks @samme)
- When the Sprite Sheet parser results in zero frames, the warning will now tell you the texture name that caused it (thanks @samme)
KeyboardPlugin.checkDown
didn't set theduration
to zero if the parameter was omitted, causing it to always return false. Fix #5146 (thanks @lozzajp)- If you passed in an array of
children
when creating a Group, they were not added and removed correctly. Fix #5151 (thanks @samme) - When using HTML5 Audio with
pauseOnBlur
(the default), if you play a sound, schedule stopping the sound (e.g., timer, tween complete callback), leave the page, and return to the page, the soundstop()
will error (thanks @samme) - Using a Render Texture when you're also using the headless renderer would cause an error (thanks @samme)
Ellipse.setWidth
would incorrectly set thexRadius
to the diameter (thanks @rexrainbow)Ellipse.setHeight
would incorrectly set theyRadius
to the diameter (thanks @rexrainbow)- When specifically setting the
parent
property in the Game Config tonull
the canvas was appended to the document body, when it should have been ignored (allowing you to add it to the dom directly). Fix #5191 (thanks @MerganThePirate) - Containers will now apply nested masks correctly when using the Canvas Renderer specifically (thanks @scott20145)
- Calling
Scale.startFullScreen
would fail in Safari on Mac OS, throwing afullscreenfailed
error. It now triggers fullscreen mode correctly, as on other browsers. Fix #5143 (thanks @samme @novaknole) - Calling
setCrop
on a Matter Physics Sprite would throw a TypeError, but will now crop correctly. Not that it only crops the texture, the body is unaffected. Fix #5211 (thanks @MatthewRorke @samme) - The Static Tilemap Layer would ignore the layer rotation and parent transform when using WebGL (but worked in Canvas). Both modes now work in the same manner (thanks @cruzdanilo)
- Calling
getTextBounds
on a BitmapText object would return the incorrect values if the origin had been changed, but the text itself had not, as it was using out of date dimensions. Changing the origin now automatically triggers BitmapText to be dirty, forcing the bounds to be refreshed. Fix #5121 (thanks @thenonamezz) - The ISO Triangle shape would skip rendering the left side of the first triangle in the batch. It now renders all ISO Triangles correctly. Fix #5164 (thanks @mattjennings)
Examples, Documentation and TypeScript
My thanks to the following for helping with the Phaser 3 Examples, Docs and TypeScript definitions, either by reporting errors, fixing them or helping author the docs:
@samme @SanderVanhove @SirJosh3917 @mooreInteractive @A-312 @lozzajp @mikewesthad @j-waters @futuremarc
Phaser v3.24.0
Arcade Physics New Features, Updates and Fixes
- When colliding physics groups with the search tree enabled, there was an unnecessary intersection test for each body returned by the search (thanks @samme)
- When doing an overlap collision, there was an unnecessary intersection test for each pair of overlapping bodies (thanks @samme)
- Sprite vs. Static Group collision tests now always use the static tree (thanks @samme)
- Fixed a bug where if you added a static body to a sprite with scale ≠ 1, the body position was incorrect (thanks @samme)
- If you passed in an array of
children
when creating a Physics Group, they didn't receive bodies. Fix #5152 (thanks @samme) - New types allow for better docs / TypeScript defs especially in the Factory functions:
ArcadePhysicsCallback
,GameObjectWithBody
,GameObjectWithDynamicBody
,GameObjectWithStaticBody
,ImageWithDynamicBody
,ImageWithStaticBody
,SpriteWithDynamicBody
andSpriteWithStaticBody
. Fix #4994 (thanks @samme @gnesher) Body.updateFromGameObject
is a new method that extracts the relevant code frompreUpdate
, allowing you to read the body's new position and center immediately, before the next physics step. It also letsrefreshBody
work for dynamic bodies, where previously it would error (thanks @samme)- Momentum exchange wasn't working correctly vs. immovable bodies. The movable body tended to stop. Fix #4770 (thanks @samme)
- The Body mass was decreasing the inertia instead of increasing it. Fix #4770 (thanks @samme)
- The separation vector seemed to be incorrect, causing the slip / slide collisions. The separation is now correct for circle–circle collisions (although not fully for circle–rectangle collisions), part fix #4770 (thanks @samme)
- The Arcade Body delta was incorrectly calculated on bodies created during the
update
step, causing the position to be off. Fix #5204 (thanks @zackexplosion @samme) Arcade.Components.Size.setBodySize
is a new method available on Arcade Physics Game Objects that allows you to set the body size. This replacessetSize
which is now deprecated. Fix #4786 (thanks @wingyplus)
New Features
- The Animation component has a new property
nextAnimsQueue
which allows you to sequence Sprite animations to play in order, i.e:this.mole.anims.play('digging').anims.chain('lifting').anims.chain('looking').anims.chain('lowering');
(thanks @tgroborsch) Group.setActive
is a new method that will set the active state of a Group, just like it does on other Game Objects (thanks @samme)Group.setName
is a new method that will set the name property of a Group, just like it does on other Game Objects (thanks @samme)TWEEN_STOP
is a new event dispatched by a Tween when it stops playback (thanks @samme @RollinSafary)- You can now specify an
onStop
callback when creating a Tween as part of the tween config, which is invoked when a Tween stops playback (thanks @samme @RollinSafary) - Previously, if you created a timeline and passed no tweens in the config, the timeline would be created but all config properties were ignored. Now the timeline's own properties (completeDelay, loop, loopDelay, useFrames, onStart, onUpdate, onLoop, onYoyo, onComplete, etc.) are set from the config properly (thanks @samme)
TextStyle.wordWrapWidth
lets you set the maximum width of a line of text (thanks @mikewesthad)TextStyle.wordWrapCallback
is a custom function that will is responsible for wrapping the text (thanks @mikewesthad)TextStyle.wordWrapCallbackScope
is the scope that will be applied when thewordWrapCallback
is invoked (thanks @mikewesthad)TextStyle.wordWrapUseAdvanced
controls whether or not to use the advanced wrapping algorithm (thanks @mikewesthad)KeyboardPlugin.removeAllKeys
is a new method that allows you to automatically remove all Key instances that the plugin has created, making house-keeping a little easier (thanks @samme)Math.RotateTo
is a new function that will position a point at the given angle and distance (thanks @samme)Display.Bounds.GetBounds
is a new function that will return the un-transformed bounds of the given Game Object as a Rectangle (thanks @samme)
Updates
- The
Pointer.dragStartX/YGlobal
andPointer.dragX/Y
values are now populated from theworldX/Y
, which means using those values directly in Input Drag callbacks will now work when the Camera is zoomed. Fix #4755 (thanks @braindx) - The
browser
field has been added to the Phaserpackage.json
pointing to thedist/phaser.js
umd build (thanks @FredKSchott) - Calling
TimeStep.wake()
while the loop is running will now cause nothing to happen, rather than sleeping and then waking again (thanks @samme) Container.getBounds
will no longer set the temp rect bounds to the first child of the Container by default (which would error if the child had no bounds, like a Graphics object) and instead sets it as it iterates the children (thanks @blopa)File.state
will now be set to theFILE_LOADING
state while loading andFILE_LOADED
after loading (thanks @samme)BaseCamera.cull
now moves some of its calculations outside of the cull loop to speed it up (thanks @samme)SceneManager.createSceneFromInstance
had a small refactor to avoid a pointless condition (thanks @samme)
Bug Fixes
- Fixed a TypeError warning when importing JSON objects directly to the
url
argument of any of the Loader filetypes. Fix #5189 (thanks @awweather @samme) - The
NOOP
function was incorrectly imported by the Mouse and Keyboard Manager. Fix #5170 (thanks @samme @gregolai) - When Audio files failed to decode on loading, they would always show 'undefined' as the key in the error log, now they show the actual key (thanks @samme)
- When the Sprite Sheet parser results in zero frames, the warning will now tell you the texture name that caused it (thanks @samme)
KeyboardPlugin.checkDown
didn't set theduration
to zero if the parameter was omitted, causing it to always return false. Fix #5146 (thanks @lozzajp)- If you passed in an array of
children
when creating a Group, they were not added and removed correctly. Fix #5151 (thanks @samme) - When using HTML5 Audio with
pauseOnBlur
(the default), if you play a sound, schedule stopping the sound (e.g., timer, tween complete callback), leave the page, and return to the page, the soundstop()
will error (thanks @samme) - Using a Render Texture when you're also using the headless renderer would cause an error (thanks @samme)
Ellipse.setWidth
would incorrectly set thexRadius
to the diameter (thanks @rexrainbow)Ellipse.setHeight
would incorrectly set theyRadius
to the diameter (thanks @rexrainbow)- When specifically setting the
parent
property in the Game Config tonull
the canvas was appended to the document body, when it should have been ignored (allowing you to add it to the dom directly). Fix #5191 (thanks @MerganThePirate) - Containers will now apply nested masks correctly when using the Canvas Renderer specifically (thanks @scott20145)
- Calling
Scale.startFullScreen
would fail in Safari on Mac OS, throwing afullscreenfailed
error. It now triggers fullscreen mode correctly, as on other browsers. Fix #5143 (thanks @samme @novaknole) - Calling
setCrop
on a Matter Physics Sprite would throw a TypeError, but will now crop correctly. Not that it only crops the texture, the body is unaffected. Fix #5211 (thanks @MatthewRorke @samme) - The Static Tilemap Layer would ignore the layer rotation and parent transform when using WebGL (but worked in Canvas). Both modes now work in the same manner (thanks @cruzdanilo)
- Calling
getTextBounds
on a BitmapText object would return the incorrect values if the origin had been changed, but the text itself had not, as it was using out of date dimensions. Changing the origin now automatically triggers BitmapText to be dirty, forcing the bounds to be refreshed. Fix #5121 (thanks @thenonamezz) - The ISO Triangle shape would skip rendering the left side of the first triangle in the batch. It now renders all ISO Triangles correctly. Fix #5164 (thanks @mattjennings)
Examples, Documentation and TypeScript
My thanks to the following for helping with the Phaser 3 Examples, Docs and TypeScript definitions, either by reporting errors, fixing them or helping author the docs:
@samme @SanderVanhove @SirJosh3917 @mooreInteractive @A-312 @lozzajp @mikewesthad @j-waters @futuremarc
Phaser v3.23.0
JSDocs
The entire Phaser 3 API now has 100% complete JSDoc coverage!
The following sections had their documentation completed in this release:
- Animations
- Create
- Curves
- Geom
- Math
- Renderer
- Textures
- Tilemaps
Removed
The following features have been removed in this version of Phaser:
- Impact Physics has been removed completely and is no longer a choice of physics system. The resulting
Scene.impact
property and Impact config object have also been removed.
Deprecated
The following features are now deprecated and will be removed in a future version of Phaser:
- The Light Pipeline and associated components will be removed. This feature was never properly finished and adds too much redundant, non-optional code into the core API. The ability to load normal maps alongside textures will remain, for use in your own lighting shaders, which gives you far more control over the final effect.
New: Rope Game Object
This version of Phaser contains the brand new Rope Game Object. A Rope is a special kind of Game Object that has a repeating texture that runs in a strip, either horizontally or vertically. Unlike a Sprite, you can define how many vertices the Rope has, and can modify each of them during run-time, allowing for some really lovely effects.
Ropes can be created via the Game Object Factory in the normal way (this.add.rope()
) and you should look at the examples and documentation for further implementation details.
Note that Ropes are a WebGL only feature.
New Features
Line.GetEasedPoints
is a new function that will take a Line, a quantity, and an ease function, and returns an array of points where each point has been spaced out across the length of the Line based on the ease function given.XHRSettings.withCredentials
is a new boolean property that controls thewithCredentials
setting of the XHR Request made by the Loader. It indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies, authorization headers or TLS client certificates. You can set this on a per-file basis, or global in the Game Config.Config.loaderWithCredentials
is the new global setting forXHRSettings.withCredentials
.Camera.renderToGame
is a new property used in conjunction withrenderToTexture
. It controls if the Camera should still render to the Game canvas after rendering to its own texture or not. By default, it will render to both, but you can now toggle this at run-time.Camera.setRenderToTexture
has a new optional parameterrenderToGame
which sets theCamera.renderToGame
property, controlling if the Camera should render to both its texture and the Game canvas, or just its texture.- The free version of Texture Packer exports a
pivot
property when using JSON Array or Hash, however the Texture Packer Phaser export uses theanchor
property. This update allows the loaders to work with either property, regardless of which export you use (thanks @veleek) get()
is a new method in the HTML and Web Audio Sound Managers that will get the first sound in the manager matching the given key, if any (thanks @samme)getAll()
is a new method in the HTML and Web Audio Sound Managers that will get all sounds in the manager matching the given key, if any (thanks @samme)removeAll()
is a new method in the HTML and Web Audio Sound Managers that will remove all sounds in the manager, destroying them (thanks @samme)stopByKey()
is a new method in the HTML and Web Audio Sound Managers that will stop any sound in the manager matching the given key, if any (thanks @samme)Rectangle.FromXY
is a new function that will create the smallest Rectangle containing two coordinate pairs, handy for marquee style selections (thanks @samme)PathFollower.pathDelta
is a new property that holds the distance the follower has traveled from the previous point to the current one, at the last update (thanks @samme)Vector2.fuzzyEquals
is a new method that will check whether the Vector is approximately equal to a given Vector (thanks @samme)Vector2.setAngle
is a new method that will set the angle of the Vector (thanks @samme)Vector2.setLength
is a new method that will set the length, or magnitude of the Vector (thanks @samme)Vector2.normalizeLeftHand
is a new method that will rotate the Vector to its perpendicular, in the negative direction (thanks @samme)Vector2.limit
is a new method that will limit the length, or magnitude of the Vector (thanks @samme)Vector2.reflect
is a new method that will reflect the Vector off a line defined by a normal (thanks @samme)Vector2.mirror
is a new method that will reflect the Vector across another (thanks @samme)Vector2.rotate
is a new method that will rotate the Vector by an angle amount (thanks @samme)Math.Angle.Random
is a new function that will return a random angle in radians between -pi and pi (thanks @samme)Math.Angle.RandomDegrees
is a new function that will return a random angle in degrees between -180 and 180 (thanks @samme)Physics.Arcade.World.fixedStep
is a new boolean property that synchronizes the physics fps to the rendering fps when enabled. This can help in some cases where "glitches" can occur in the movement of objects. These glitches are especially noticeable on objects that move at constant speed and the fps are not consistent. Enabling this feature disables the fps and timeScale properties of the Arcade.World class (thanks @jjcapellan)Curves.Path.getTangent
is a new method that gets a unit vector tangent at a relative position on the path (thanks @samme)DataManager.inc
is a new method that will increase a value for the given key. If the key doesn't already exist in the Data Manager then it is increased from 0 (thanks @rexrainbow)DataManager.toggle
is a new method that will toggle a boolean value for the given key. If the key doesn't already exist in the Data Manager then it is toggled from false (thanks @rexrainbow)- The Tiled parser will now recognize Tiled
point objects
and export them withpoint: true
. Equally, Sprites generated viacreateFromObjects
are now just set to the position of the Point object, using the Sprites dimensions. This is a breaking change, so if you are using Point objects andcreateFromObjects
please re-test your maps against this release of Phaser (thanks @samme) - You can now use Blob URLs when loading
Audio
objects via the Loader (thanks @aucguy) - You can now use Blob URLs when loading
Video
objects via the Loader (thanks @aucguy) - Tiled Image Collections now have rudimentary support and will create a single tileset per image. This is useful for prototyping, but should not be used heavily in production. See #4964 (thanks @gogoprog)
- When loading files using your own XHR Settings you can now use the new property
headers
to define an object containing multiple headers, all of which will be sent with the xhr request (thanks @jorbascrumps) Camera.rotateTo
is a new Camera effect that allows you to set the rotation of the camera to a given value of the duration specified (thanks @jan1za)
Updates
XHRLoader
will now use theXHRSettings.withCredentials
as set in the file or global loader config.Animation.setCurrentFrame
will no longer try to callsetOrigin
orupdateDisplayOrigin
if the Game Object doesn't have the Origin component, preventing unknown function errors.MatterTileBody
now extendsEventEmitter
, meaning you can listen to collision events from Tiles directly and it will no longer throw errors aboutgameObject.emit
not working. Fix #4967 (thanks @reinildo)- Added
MatterJS.BodyType
toGameObject.body
type. Fix #4962 (thanks @meisterpeeps) - The
JSONHash
loader didn't load custom pivot information, butJSONArray
did. So that functionality has been duplicated into theJSONHash
file type (thanks @veleek) - When enabling a Game Object for input debug, the debug body's depth was 0. It's now set to be the same depth as the actual Game Object (thanks @mktcode)
- Spine Files can now be loaded via a manifest, allowing you to specify a prefix in the loader object and providing absolute paths to textures. Fix #4813 (thanks @FostUK @a610569731)
collideSpriteVsGroup
now exits early when the Sprite hascheckCollision.none
, skipping an unnecessary iteration of the group (thanks @samme)collideSpriteVsGroup
when looping through the tree results now skips bodies withcheckCollision.none
(thanks @samme)- When enabling a Game Object for Input Debugging the created debug shape will now factor in the position, scale and rotation of the Game Objects parent Container, if it has one (thanks @scott20145)
Bug Fixes
- The conditional checking if the
PathFollower
was at the end of the path or not was incorrect (thanks @samme) - Creating an
Arcade Physics Body
from a scaled Game Object would use the un-scaled dimensions for the body. They now use the scaled dimensions. This may be a breaking change in some games, so please be aware of it (thanks @samme) - Creating an
Arcade Physics Static Body
from a scaled Game Object would use the un-scaled dimensions for the body. They now use the scaled dimensions. This may be a breaking change in some games, so please be aware of it (thanks @samme) - The
Arcade Physics Static Body
center was incorrect after construction. Probably caused problems with circle collisions. Fix #4770 (thanks @samme) - An Arcade Physics Body
center
andposition
are now correct after construction and before preUpdate(), for any Game Object origin or scale (thanks @samme) - When calling
Body.setSize
with thecenter
parameter astrue
the calculated offset would be incorrect for scaled Game Objects. The offset now takes scaling into consideration (thanks @samme) HTML5AudioFile.load
would throw an error ...
Phaser v3.22.0
Matter Physics
All of the following are specific to the Matter Physics implementation used by Phaser:
Matter Physics New Features
- Matter Physics now has 100% JSDoc coverage! Woohoo :)
- Matter Physics now has brand new TypeScript defs included in the
types
folder :) MatterDebugConfig
is a new configuration object that contains all of the following new Matter debug settings:showAxes
- Render all of the body axes?showAngleIndicator
- Render just a single body axis?angleColor
- The color of the body angle / axes lines.showBroadphase
- Render the broadphase grid?broadphaseColor
- The color of the broadphase grid.showBounds
- Render the bounds of the bodies in the world?boundsColor
- The color of the body bounds.showVelocity
- Render the velocity of the bodies in the world?velocityColor
- The color of the body velocity line.showCollisions
- Render the collision points and normals for colliding pairs.collisionColor
- The color of the collision points.showSeparation
- Render lines showing the separation between bodies.separationColor
- The color of the body separation line.showBody
- Render the dynamic bodies in the world to the Graphics object?showStaticBody
- Render the static bodies in the world to the Graphics object?showInternalEdges
- When rendering bodies, render the internal edges as well?renderFill
- Render the bodies using a fill color.renderLine
- Render the bodies using a line stroke.fillColor
- The color value of the fill when rendering dynamic bodies.fillOpacity
- The opacity of the fill when rendering dynamic bodies, a value between 0 and 1.lineColor
- The color value of the line stroke when rendering dynamic bodies.lineOpacity
- The opacity of the line when rendering dynamic bodies, a value between 0 and 1.lineThickness
- If rendering lines, the thickness of the line.staticFillColor
- The color value of the fill when rendering static bodies.staticLineColor
- The color value of the line stroke when rendering static bodies.showSleeping
- Render any sleeping bodies (dynamic or static) in the world to the Graphics object?staticBodySleepOpacity
] - The amount to multiply the opacity of sleeping static bodies by.sleepFillColor
- The color value of the fill when rendering sleeping dynamic bodies.sleepLineColor
- The color value of the line stroke when rendering sleeping dynamic bodies.showSensors
- Render bodies or body parts that are flagged as being a sensor?sensorFillColor
- The fill color when rendering body sensors.sensorLineColor
- The line color when rendering body sensors.showPositions
- Render the position of non-static bodies?positionSize
- The size of the rectangle drawn when rendering the body position.positionColor
- The color value of the rectangle drawn when rendering the body position.showJoint
- Render all world constraints to the Graphics object?jointColor
- The color value of joints whenshowJoint
is set.jointLineOpacity
- The line opacity when rendering joints, a value between 0 and 1.jointLineThickness
- The line thickness when rendering joints.pinSize
- The size of the circles drawn when rendering pin constraints.pinColor
- The color value of the circles drawn when rendering pin constraints.springColor
- The color value of spring constraints.anchorColor
- The color value of constraint anchors.anchorSize
- The size of the circles drawn as the constraint anchors.showConvexHulls
- When rendering polygon bodies, render the convex hull as well?hullColor
- The color value of hulls whenshowConvexHulls
is set.World.renderBody
is a new method that will render a single Matter Body to the given Graphics object. This is used internally during debug rendering but is also public. This allows you to control which bodies are rendered and to which Graphics object, should you wish to use them in-game and not just during debugging.World.renderConstraint
is a new method that will render a single Matter Constraint, such as a pin or a spring, to the given Graphics object. This is used internally during debug rendering but is also public. This allows you to control which constraints are rendered and to which Graphics object, should you wish to use them in-game and not just during debugging.World.renderConvexHull
is a new method that will render the convex hull of a single Matter Body, to the given Graphics object. This is used internally during debug rendering but is also public. This allows you to control which hulls are rendered and to which Graphics object, should you wish to use them in-game and not just during debugging.World.renderGrid
is a new method that will render the broadphase Grid to the given graphics instance.World.renderBodyBounds
is a new method that will render the bounds of all the given bodies to the given graphics instance.World.renderBodyAxes
is a new method that will render the axes of all the given bodies to the given graphics instance.World.renderBodyVelocity
is a new method that will render a velocity line for all the given bodies to the given graphics instance.World.renderSeparations
is a new method that will render the separations in the current pairs list to the given graphics instance.World.renderCollisions
is a new method that will render the collision points and normals in the current pairs list to the given graphics instance.World.getAllBodies
is a new method that will return all bodies in the Matter World.World.getAllConstraints
is a new method that will return all constraints in the Matter World.World.getAllComposites
is a new method that will return all composites in the Matter World.MatterPhysics.composite
is a new reference to theMatter.Composite
module for easy access from within a Scene.MatterPhysics.detector
is a new reference to theMatter.Dectector
module for easy access from within a Scene.MatterPhysics.grid
is a new reference to theMatter.Grid
module for easy access from within a Scene.MatterPhysics.pair
is a new reference to theMatter.Pair
module for easy access from within a Scene.MatterPhysics.pairs
is a new reference to theMatter.Pairs
module for easy access from within a Scene.MatterPhysics.query
is a new reference to theMatter.Query
module for easy access from within a Scene.MatterPhysics.resolver
is a new reference to theMatter.Resolver
module for easy access from within a Scene.MatterPhysics.sat
is a new reference to theMatter.SAT
module for easy access from within a Scene.MatterPhysics.constraint
is a new reference to theMatter.Constraint
module for easy access from within a Scene.MatterPhysics.composites
is a new reference to theMatter.Composites
module for easy access from within a Scene.MatterPhysics.axes
is a new reference to theMatter.Axes
module for easy access from within a Scene.MatterPhysics.bounds
is a new reference to theMatter.Bounds
module for easy access from within a Scene.MatterPhysics.svg
is a new reference to theMatter.Svg
module for easy access from within a Scene.MatterPhysics.vector
is a new reference to theMatter.Vector
module for easy access from within a Scene.MatterPhysics.vertices
is a new reference to theMatter.Vertices
module for easy access from within a Scene.BEFORE_ADD
is a new Event dispatched byMatter.World
when a Body or Constraint is about to be added to the World.AFTER_ADD
is a new Event dispatched byMatter.World
when a Body or Constraint has been added to the World.BEFORE_REMOVE
is a new Event dispatched byMatter.World
when a Body or Constraint is about to be removed from the World.AFTER_REMOVE
is a new Event dispatched byMatter.World
when a Body or Constraint has been removed from the World.Body.render.lineOpacity
is a new property on the Matter Body object that allows for custom debug rendering.Body.render.lineThickness
is a new property on the Matter Body object that allows for custom debug rendering.Body.render.fillOpacity
is a new property on the Matter Body object that allows for custom debug rendering.World.setCompositeRenderStyle
is a new method that lets you quickly set the render style values on the children of the given compposite.World.setBodyRenderStyle
is a new method that lets you quickly set the render style values on the given Body.World.setConstraintRenderStyle
is a new method that lets you quickly set the render style values on the given Constraint.- You can now set
restingThresh
in the Matter Configuration file to adjust the Resolver property. - You can now set
restingThreshTangent
in the Matter Configuration file to adjust the Resolver property. - You can now set
positionDampen
in the Matter Configuration file to adjust the Resolver property. - You can now set
positionWarming
in the Matter Configuration file to adjust the Resolver property. - You can now set
frictionNormalMultiplier
in the Matter Configuration file to adjust the Resolver property. MatterPhysics.containsPoint
is a new method that returns a boolean if any of the given bodies intersect with the given point.MatterPhysics.intersectPoint
is a new method that checks which bodies intersect with the given point and returns them.MatterPhysics.intersectRect
is a new method that checks which bodies intersect with the given rectangular area, and returns them. Optionally, it can check which bodies are outside of the area.MatterPhysics.intersectRay
is a new method that checks which bodies intersect with the given ray segment and returns them. Optionally, you can set the width of the ray.MatterPhysics.intersectBody
is a new method that checks which bodies intersect with...
Phaser v3.21.0
New Features
- You can now specify the mipmap filter level to be used when creating WebGL textures. This can be set in the Game Config using the new
mipmapFilter
property, which is a string, such as 'NEAREST_MIPMAP_NEAREST'. Or, you can set the newWebGLRenderer.mipmapFilter
property to a valid GLenum. If you set it on the renderer, it will only impact any textures loaded after it has been set, so do so in your Sceneinit
method if you want it to be used for textures you're about to load. By changing the mipmap level you can drastically improve the quality when reducing large textures. Please note, due to WebGL1 limitations, this only works on power-of-two sized textures. It also works on textures created from Canvas, Videos or RenderTextures. BitmapText.setMaxWidth
is a new method that allows you to set a maximum width (in pixels) for the BitmapText to take up when rendering. Lines of text longer thanmaxWidth
will be wrapped, based on whitespace, to the next line. This allows you to do word-wrapping on BitmapText objects, something only previously possible on Text objects.BitmapText.wordWrapCharCode
is a new property that works withsetMaxWidth
that allows you to control which character code causes a line-wrap. By default it is 32 (a space character).ArcadePhysics.closest
now has an optionaltargets
argument. The targets can be any Arcade Physics Game Object, Body or Static Body and it will return only the closet target from those given (thanks @samme)ArcadePhysics.furthest
now has an optionaltargets
argument. The targets can be any Arcade Physics Game Object, Body or Static Body and it will return only the furthest target from those given (thanks @samme)Tilemaps.Parsers.Tiled.CreateGroupLayer
is a new function that parses a Tiled group layer and adds in support for Tiled layer groups (introduced in Tiled 1.2.0). Feature #4099 (thanks @Babeetlebum @Olliebrown)- The Tilemap system now supports infinite Tilemaps from the Tiled map editor (thanks @Olliebrown)
Tilemap.getImageLayerNames
is a new method that returns a list of all valid imagelayer names loaded in the Tilemap (thanks @Olliebrown)Tilemap.getObjectLayerNames
is a new method that returns a list of all valid objectgroup names loaded in the Tilemap (thanks @Olliebrown)Tilemap.getTileLayerNames
is a new method that returns a list of all valid tilelayer names loaded in the Tilemap (thanks @Olliebrown)- When
forceSetTimeOut
is set totrue
in the Game Config, you can now set the target frame rate by setting thefps.target
value (thanks @pavels) - Videos can now be loaded from a data URI, allowing for base64 encoded videos to be used in the Loader instead of file based ones. Although, as with all base64 encoded data, we strongly recommend against this (thanks @apasov)
Math.MIN_SAFE_INTEGER
is a new math const that stores the minimum safe integer for browsers that don't provide this, such as IE (thanks @jronn)Math.MAX_SAFE_INTEGER
is a new math const that stores the maximum safe integer for browsers that don't provide this, such as IE (thanks @jronn)KeyCodes.NUMPAD_ADD
has been added to the keycodes list (thanks @Martin-Antonov)KeyCodes.NUMPAD_SUBTRACT
has been added to the keycodes list (thanks @Martin-Antonov)Video.removeVideoElementOnDestroy
is a new boolean property that allows you to control if the Video element is removed from the DOM when the Video Game Object is destroyed.Actions.SetScrollFactor
is a new Action that will set the scroll factor on an array of Game Objects, including stepped incremental changes per item (thanks @rexrainbow)Actions.SetScrollFactorX
is a new Action that will set the horizontal scroll factor on an array of Game Objects, including stepped incremental changes per item (thanks @rexrainbow)Actions.SetScrollFactorY
is a new Action that will set the horizontal scroll factor on an array of Game Objects, including stepped incremental changes per item (thanks @rexrainbow)- The
Group
config object now supports use of thesetScrollFactor
property to set the value on each child of the Group (thanks @rexrainbow) Group.propertyValueSet
is a new method that sets a given property on each Group member (thanks @rexrainbow)Group.propertyValueInc
is a new method that adds an amount to a given property on each Group member (thanks @rexrainbow)Group.setX
is a new method that sets the x coordinate on each Group member (thanks @rexrainbow)Group.setY
is a new method that sets the y coordinate on each Group member (thanks @rexrainbow)Group.setXY
is a new method that sets the x and y coordinate on each Group member (thanks @rexrainbow)Group.incX
is a new method that increments the x coordinate on each Group member (thanks @rexrainbow)Group.incY
is a new method that increments the y coordinate on each Group member (thanks @rexrainbow)Group.incXY
is a new method that increments the x and y coordinate on each Group member (thanks @rexrainbow)Group.shiftPosition
is a new method that iterates the Group members and shifts the position of each to the previous members position (thanks @rexrainbow)Group.angle
is a new method that sets the angle property on each Group member (thanks @rexrainbow)Group.rotate
is a new method that sets the rotation property on each Group member (thanks @rexrainbow)Group.rotateAround
is a new method that rotates each Group member around the given point, by the given angle (thanks @rexrainbow)Group.rotateAroundDistance
is a new method that rotates each Group member around the given point, by the given angle and distance (thanks @rexrainbow)Group.setAlpha
is a new method that sets the alpha property on each Group member (thanks @rexrainbow)Group.setTint
is a new method that sets the tint property on each Group member (thanks @rexrainbow)Group.setOrigin
is a new method that sets the origin property on each Group member (thanks @rexrainbow)Group.scaleX
is a new method that sets the x scale on each Group member (thanks @rexrainbow)Group.scaleY
is a new method that sets the y scale on each Group member (thanks @rexrainbow)Group.scaleXY
is a new method that sets the x and y scale on each Group member (thanks @rexrainbow)Group.setBlendMode
is a new method that sets the blend mode on each Group member (thanks @rexrainbow)Group.setHitArea
is a new method that passes all Group members to the Input Plugin to enable them for input (thanks @rexrainbow)Group.shuffle
is a new method that shuffles all of the Group members in place (thanks @rexrainbow)Group.setVisible
is a new method that sets the visible state on each Group member (thanks @rexrainbow)WebAudioSoundManager.setAudioContext
is a new method that allows you to set the Sound Manager Audio Context to a different context instance. It will also disconnect and re-create the gain nodes on the new context.Group.type
is a new property that holds a string-based name of the Game Object type, as with other GO's (thanks @samme)Arade.Group.type
is a new property that holds a string-based name of the Game Object type, as with other GO's (thanks @samme)Arcade.StaticGroup.type
is a new property that holds a string-based name of the Game Object type, as with other GO's (thanks @samme)ArcadePhysics.overlapCirc
is a new method that allows you to return an array of all Arcade Physics bodies that overlap with the given circular area of the world. It can return either dynamic or static bodies, or a mixture of both (thanks @samme)
Updates
Curve.getPoints
can now take an optional array as the 3rd parameter in which to store the points results (thanks @rexrainbow)Line.arcLengthDivisions
now overrides the default Curve value and is set to 1 to optimize the amount of points returned for a Line curve (thanks @rexrainbow)ArcadePhysics.closest
will now no longer ever return the source in the target results (thanks @samme)ArcadePhysics.furthest
will now no longer ever return the source in the target results (thanks @samme)RequestAnimationFrame.target
is a new property that controls the fps rate (in ms) when setTimeout is used (thanks @pavels)- The
WebAudioSoundManager.unlock
method will now listen forkeydown
events in order to unlock the Audio Context, as well as touch and pointer events, making it more accessible (thanks Nick Tipping) - The
requestAnimationFrame
polyfill no longer expects a Browserify environment and useswindow
through-out, it also no longer adds in the same as performance.now does. BitmapText.getTextBounds
didn't reset the dirty flag, causing theGetBitmapTextSize
function to be called every time the Bitmap Text was rendered. With enough text objects on-screen this could negatively impact performance. The flag is now reset every time the bounds are recalculated.
Bug Fixes
- The Spine Plugin was not clearing down the resize event listener in WebGL, causing it to still fire even if the Scene was closed. Fix #4808 (thanks @RollinSafary)
- When a game is created with the HEADLESS renderer,
Game.destroy()
had no effect and the game kept on running. Now it destroys itself properly. Fix #4804 (thanks @samme) DOM.GetScreenOrientation
was returning the wrong consts from the Scale Manager (thanks @jcyuan)- When using
Input.enableDebug
on Game Objects it would not render the debug graphic correctly if the hit area had been offset. It now adjusts the debug correctly for all common hit-area geometry types. Fix #4722 (thanks @HaoboZ @Olliebrown) - Light2D was not properly working for DynamicTilemapLayers due to a change in the way tilesets were stored, throwing an Uncaught TypeError at runtime. This is now handled correctly. Fix #4167 #4079 (thanks @koljakutschera @blackjack26 @kainage)
Input.dragDistanceThreshold
was not workin...
Phaser 3.20.1
Updates
- The
remove-files-webpack-plugin
plugin has been moved to a devDependency (thanks @noseglid)
Bug Fixes
UpdateList.shutdown
wasn't removing the Scene Update event listener, causing actions to be multiplied on Scene restart (such as animation playback). Fix #4799 (thanks @jronn)Container.mask
wouldn't render in WebGL due to a change in the way child masks were handled. Container masking now works again as in 3.19. Fix #4803 (thanks @paulsymphony)DynamicTilemapLayer.setCollision
would cause anindexOf
error when trying to access the layer data. Fix #4800 (thanks @PavelMishin)SceneManager.run
(and consequentlyScenePlugin.run
) was using an out-dated way of checking if a Scene was paused before trying to resume it, causing a Scene to be started again instead of resumed. It now uses theSystems.isPaused
function instead. Fix #3931 (thanks @alexeymolchan)
Examples, Documentation and TypeScript
My thanks to the following for helping with the Phaser 3 Examples, Docs and TypeScript definitions, either by reporting errors, fixing them or helping author the docs:
Phaser v3.20.0
Video Game Object
This is a new Game Object is capable of handling playback of a previously loaded video from the Phaser Video Cache,
or playing a video based on a given URL. Videos can be either local, or streamed:
preload () {
this.load.video('pixar', 'nemo.mp4');
}
create () {
this.add.video(400, 300, 'pixar');
}
To all intents and purposes, a video is a standard Game Object, just like a Sprite. And as such, you can do
all the usual things to it, such as scaling, rotating, cropping, tinting, making interactive, giving a
physics body, etc.
Transparent videos are also possible via the WebM file format. Providing the video file has was encoded with
an alpha channel, and providing the browser supports WebM playback (not all of them do), then it willl render
in-game with full transparency.
You can also save a video to the Texture Manager, allowing other Game Objects to use it as their texture,
including using it as a sampler2D input for a shader.
See the Video Game Object class for more details. Other Video related changes are as follows:
Loader.FileTypes.VideoFile
is a new Video File Loader File Type, used for preloading videos as streams or blobs.WebGLRenderer.createVideoTexture
is a new method that will create a WebGL Texture from the given Video Element.WebGLRenderer.updateVideoTexture
is a new method that will update a WebGL Texture from the given Video Element.TextureSource.isVideo
is a new boolean property that is set when the Texture Source is backed by an HTML Video Element.Cache.video
is a new global cache that store loaded Video content.Device.Video.h264Video
has been renamed toDevice.Video.h264
to keep it in-line with the Audio Device names.Device.Video.hlsVideo
has been renamed toDevice.Video.hls
to keep it in-line with the Audio Device names.Device.Video.mp4Video
has been renamed toDevice.Video.mp4
to keep it in-line with the Audio Device names.Device.Video.oggVideo
has been renamed toDevice.Video.ogg
to keep it in-line with the Audio Device names.Device.Video.vp9Video
has been renamed toDevice.Video.vp9
to keep it in-line with the Audio Device names.Device.Video.webmVideo
has been renamed toDevice.Video.webm
to keep it in-line with the Audio Device names.
Spine Plugin
- The Spine runtimes have been updated to 3.8. Please note that Spine runtimes are not backwards compatible. Animations exported with Spine 3.7 (or earlier) will need re-exporting with 3.8 in order to work with the new runtimes.
- Fixed a bug with the binding of the Spine Plugin causing the GameObjectFactory to remain bound to the first instance of the plugin, causing Scene changes to result in blank Spine Game Objects. Fix #4716 (thanks @olilanz)
- Fixed a bug with the caching of the Spine Texture Atlases, causing shader errors when returning from one Scene to another with a cached Texture Atlas.
- The WebGL Scene Renderer is now only disposed if the Scene is destroyed, not just shut-down.
- The Spine Game Object will no longer set the default skin name to be 'default', it will leave the name empty. Fix #4764 (thanks @jonchun @badlogic)
- Thanks to a fix inside the Container WebGLRenderer, a bug was crushed which involved multiple Containers in a Scene, with Spine objects, from causing run-time errors. Fix #4710 (thanks @nalgorry)
- Using
Loader.setPath
to define the Spine assets locations could error if trying to load multiple files from different folders. It will now retain the path state at the time of invocation, rather than during the load. - When loading Spine files that used the same internal image file names, only the first file would successfully load. Now, all files load correctly.
Facebook Instant Games Plugin
- Calling
showAd
orshowVideoAd
will now check to see if the ad has already been displayed, and skip it when iterating the ads array, allowing you to display an ad with the same Placement ID without preloading it again. Fix #4728 (thanks @NokFrt) - Calling
gameStarted
in a game that doesn't load any assets would cause the error{code: "INVALID_OPERATION", message: "Can not perform this operation before game start."}
. The plugin will now has a new internal methodgameStartedHandler
and will redirect the flow accordingly based on asset loading. Fix #4550 (thanks @bchee) - The documentation for the
chooseContext
method has been fixed. Fix #4425 (thanks @krzysztof-grzybek) Leaderboard.getConnectedScores
incorrectly specified two parameters, neither of which were used. Fix #4702 (thanks @NokFrt)Leaderboard
extends Event Emitter, which was missing in the TypeScript defs. Fix #4703 (thanks @NokFrt)
Arcade Physics Updates
@BenjaminDRichards and the GameFroot team contributed the following updates to Arcade Physics, which fixes 3 issues encountered when the framerate drops below 60 (technically, any time when multiple physics steps run per frame, so if physics FPS is above 60 this will also occur.)
Issue 1: Friction starts to flip out. Objects on moving platforms get pushed ahead of the platform and "catch" on the leading edge.
Issue 2: Physics objects start to dip into the floor. In the "Before" demo, the camera is locked to the player, so this appears as the entire world starting to shake up and down.
Issue 3: When objects dip into the floor, their "rest velocity" is non-zero. This can affect debug and other logic.
Body.prevFrame
is a new vector allowing a Body to distinguish between frame-length changes and step-length changes. Several steps may run for every frame, particularly when fps is low.Body._reset
flag was removed and replaced it with a check ofBody.moves
. The flag only turned on whenmoves
was true, and never turned off.- Added a reset of
prev
in Arcade.Body#step. This fixes the friction issue. - Stopped the
Body.postUpdate
method from setting_dx
,_dy
, andprev
. They remain in the state they were at the end of the last physics step. This will affect the delta methods, which are documented to provide step-based data (not frame-based data); they now do so. However, because several steps may run per frame, you can't interrogate every step unless you're running functions based on physics events like collisions. You'll just see the latest step. This should partially balance out the extra load of resetting prev. - Added a zero-out of stepsLastFrame in Arcade.World#postUpdate, which would otherwise never zero out and keep running at least one pass per frame. This should improve performance when frames can be skipped.
- Removed
blocked
checks fromTileCheckX
andTileCheckY
. Originally, this prevented multiple checks when an object had come to rest on a floor. However, when multiple steps run per frame, the object will accelerate again, the floor won't stop it on steps 2+, and it will end the frame a short distance into the floor. Removing the blocked checks will fix the floor dip issue and the rest velocity issue. Although this opens up multiple checks, this is probably very rare: how many times does an object hit two different floors in a single frame?
In combination these updates fix issues #4732 and #4672. My thanks to @BenjaminDRichards and @falifm.
New Features
GameConfig.antialiasGL
is a new boolean that allows you to set theantialias
property of the WebGL context during creation, without impacting any subsequent textures or the canvas CSS.InteractiveObject.alwaysEnabled
is a new boolean that allows an interactive Game Object to always receive input events, even if it's invisible or won't render.Bob.setTint
is a new method that allows you to set the tint of a Bob object within a Blitter. This is then used by the Blitter WebGL Renderer (thanks @rexrainbow)- The
UpdateList
now emits two new events: 'add' and 'remove' when children are added and removed from it. Fix #3487 (thanks @hexus) - The
Tilemap.setCollision
method has a new optional boolean parameterupdateLayer
. If set totrue
, it will update all of the collision settings of all tiles on the layer. Iffalse
it will skip doing this, which can be a huge performance boost in situations where the layer tiles haven't been modified and you're just changing collision flags. This is especially suitable for maps using procedural generated tilemaps, infinite tilemaps, multiplayer tilemaps, particularly large tilemaps (especially those dyanmic in nature) or who otherwise intend to index collisions before the tiles are loaded. This update also added the new parameter to theSetCollision
,SetCollisionBetween
andDynamicTilemapLayer.setCollision
methods (thanks @tarsupin) ArcadePhysics.Body.setBoundsRectangle
is a new method that allows you to set a custom bounds rectangle for any Body to use, rather than the World bounds, which is the default (thanks @francois-n-dream)ArcadePhysics.Body.customBoundsRectangle
is a new property used for custom bounds collision (thanks @francois-n-dream)- The Arcade Physics Group has a new config object property
customBoundsRectangle
which, if set, will set the custom world bounds for all Bodies that Group creates (thanks @francois-n-dream) WebGLRenderer.createTexture2D
has a new optional parameterflipY
which sets theUNPACK_FLIP_Y_WEBGL
flag of the uploaded texture.WebGLRenderer.canvasToTexture
has a new optional parameterflipY
which sets theUNPACK_FLIP_Y_WEBGL
flag of the uploaded texture.WebGLRenderer.createCanvasTexture
is a new method that will create a WebGL Texture based on the given Canvas Element.WebGLRenderer.updateCanvasTexture
is a new method that will update an existing WebGL Texture based on the given Canvas Element.WebGLRenderer.createVideoTexture
is a new method that will create a WebGL Texture based on the given Video Element.WebGLRenderer.updateVideoTexture
i...
Phaser v3.19.0
Version 3.19.0 - Naofumi - 8th August 2019
Tween Updates
- All Tween classes and functions have 100% complete JSDocs :)
StaggerBuilder
is a new function that allows you to define a staggered tween property. For example, as part of a tween config:delay: this.tweens.stagger(500)
would stagger the delay by 500ms for every target of the tween. You can also provide a range:delay: this.tweens.stagger([ 500, 1000 ])
which is spread across all targets. Finally, you can provide a Stagger Config object as the second argument. This allows you to define a stagger grid, direction, starting value and more. Please see the API Docs and new Examples for further details.Tween
now extends the Event Emitter class, allowing it to emit its own events and be listened to.Tween.ACTIVE_EVENT
is a new event that is dispatched when a tween becomes active. Listen to it withtween.on('active')
.Tween.COMPLETE_EVENT
is a new event that is dispatched when a tween completes or is stopped. Listen to it withtween.on('complete')
.Tween.LOOP_EVENT
is a new event that is dispatched when a tween loops, after any loop delay expires. Listen to it withtween.on('loop')
.Tween.REPEAT_EVENT
is a new event that is dispatched when a tween property repeats, after any repeat delay expires. Listen to it withtween.on('repeat')
.Tween.START_EVENT
is a new event that is dispatched when a tween starts. Listen to it withtween.on('start')
.Tween.UPDATE_EVENT
is a new event that is dispatched when a tween property updates. Listen to it withtween.on('update')
.Tween.YOYO_EVENT
is a new event that is dispatched when a tween property yoyos, after any hold delay expires. Listen to it withtween.on('yoyo')
.Tween.onActive
is a new callback that is invoked the moment the Tween Manager brings the tween to life, even though it may not have yet started actively tweening anything due to delay settings.Tween.onStart
is now only invoked when the Tween actually starts tweening a value. Previously, it was invoked as soon as the Tween Manager activated the Tween. This has been recoded and this action is now handled by theonActive
callback. Fix #3330 (thanks @wtravO)Tween.seek
has been rewritten so you can now seek to any point in the Tween, regardless of repeats, loops, delays and hold settings. Seeking will not invoke any callbacks or events during the seek. Fix #4409 (thanks @cristib84)- You can now set
from
andto
values for a property, i.e.alpha: { from: 0, to: 1 }
which would set the alpha of the target to 0 and then tween it to 1 after any delays have expired. Fix #4493 (thanks @BigZaphod) - You can now set
start
andto
values for a property, i.e.alpha: { start: 0, to: 1 }
which would set the alpha of the target to 0 immediately, as soon as the Tween becomes active, and then tween it to 1 over the duration of the tween. - You can now set
start
,from
andto
values for a property, i.e.alpha: { start: 0, from: 0.5, to: 1 }
which would set the alpha of the target to 0 immediately, as soon as the Tween becomes active, then after any delays it would set the alpha to 0.5 and then tween it to 1 over the duration of the Tween. Tween.hasStarted
is a new property that holds a flag signifying if the Tween has started or not. A Tween that has started is one that is actively tweening a property and not just in a delayed state.Tween.startDelay
is a new property that is set during the Tween init to hold the shortest possible time before the Tween will start tweening a value. It is decreased each update until it hits zero, after which theonStart
callback is invoked.Tween.init
andTween.play
have been rewritten so they are not run multiple times when a Tween is paused before playback, or is part of a Timeline. This didn't cause any problems previously, but it was a redundant duplication of calls.Tween.onLoop
will now be invoked after theloopDelay
has expired, if any was set.Tween.onRepeat
will now be invoked after therepeatDelay
has expired, if any was set.easeParams
would be ignored for tweens that didn't use a string for the ease function name. Fix #3826 (thanks @SBCGames)- You can now specify
easeParams
for any custom easing function you wish to use. Fix #3826 (thanks @SBCGames) - All changes to
Tween.state
are now set before any events or callbacks, allowing you to modify the state of the Tween in those handlers (thanks @Cudabear) Tween.dispatchTweenEvent
is a new internal method that handles dispatching the new Tween Events and callbacks. This consolidates a lot of duplicate code into a single method.Tween.dispatchTweenDataEvent
is a new internal method that handles dispatching the new TweenData Events and callbacks. This consolidates a lot of duplicate code into a single method.Tween.isSeeking
is a new internal boolean flag that is used to keep track of the seek progress of a Tween.Timeline.onLoop
will now be invoked after theloopDelay
has expired, if any was set.Timeline.onComplete
will now be invoked after thecompleteDelay
has expired, if any was set.- All changes to
Timeline.state
are now set before any events or callbacks, allowing you to modify the state of the Timeline in those handlers. - The
TIMELINE_LOOP_EVENT
has had theloopCounter
argument removed from it. It didn't actually send the number of times the Timeline had looped (it actually sent the total remaining). - When a TweenData completes it will now set the
current
property to be exactly eitherstart
orend
depending on playback direction. - When a TweenData completes it will set the exact
start
orend
value into the target property. TweenData
has a new function signature, with the newindex
andgetActive
arguments added to it.TweenBuilder
has been updated to set these, but if you create any TweenData objects directly, use the new signature.TweenData.getActiveValue
is a new property that, if not null, returns a value to immediately sets the property value to on activation.GetEaseFunction
, and by extension anything that uses it, such as setting the ease for a Tween, will now accept a variety of input strings as valid. You can now use lower-case, such asback
, and omit the 'ease' part of the direction, such asback.in
orback.inout
.- The signature of
getStart
andgetEnd
custom property functions has changed to(target, key, value, targetIndex, totalTargets, tween)
, previously it was just(target, key, value)
. Custom functions don't need to change as the new arguments are in addition to those sent previously. - The signature of the LoadValue generator functions (such as
delay
andrepeat
) has changed to(target, key, value, targetIndex, totalTargets, tween)
to match those of the custom property functions. If you used a custom generator function for your Tween configs you'll need to modify the signature to the new one. - Tweens created via
TweenManager.create
wouldn't start whenTween.play
was called without first making them active manually. They now start automatically. Fix #4632 (thanks @mikewesthad)
Spine Updates
The Spine Plugin is now 100% complete. It has been updated to use the Spine 3.7 Runtimes. Improvements have been made across the entire plugin, including proper batched rendering support in WebGL, cleaner skin and slot functions and lots and lots of updates. It's fully documented and there are lots of examples to be found. The following legacy bugs have also been fixed:
- Adding Spine to physics causes position to become NaN. Fix #4501 (thanks @hizzd)
- Destroying a Phaser Game instance and then re-creating it would cause an error trying to re-create Spine Game Objects ("Cannot read property get of null"). Fix #4532 (thanks @Alex-Badea)
- Rendering a Spine object when a Camera has
renderToTexture
enabled on it would cause the object to be vertically flipped. It now renders correctly in both cases. Fix #4647 (thanks @probt)
New Features
Shader.setRenderToTexture
is a new method that will redirect the Shader to render to its own framebuffer / WebGLTexture instead of to the display list. This allows you to use the output of the shader as an input for another shader, by mapping a sampler2D uniform to it. It also allows you to save the Shader to the Texture Manager, allowing you to use it as a texture for any other texture based Game Object such as a Sprite.Shader.setSampler2DBuffer
is a new method that allows you to pass a WebGLTexture directly into a Shader as a sampler2D uniform, such as when linking shaders together as buffers for each other.Shader.renderToTexture
is a new property flag that is set if you set the Shader to render to a texture.Shader.framebuffer
is a new property that contains a WebGLFramebuffer reference which is set if you set the Shader to render to a texture.Shader.glTexture
is a new property that contains a WebGLTexture reference which is set if you set the Shader to render to a texture.Shader.texture
is a new property that contains a Phaser Texture reference which is set if you set the Shader to save to the Texture Manager.TextureManager.addGLTexture
is a new method that allows you to add a WebGLTexture directly into the Texture Manager, saved under the given key.TextureSource.isGLTexture
is a new boolean property that reflects if the data backing the underlying Texture Source is a WebGLTexture or not.TextureTintPipeline.batchSprite
will now flip the UV if the TextureSource comes from a GLTexture.Math.ToXY
is a new mini function that will take a given index and return a Vector2 containing the x and y coordinates of that index within a grid.RenderTexture.glTexture
is a new property that holds a reference to the WebGL Texture being used by the Render Texture. Useful for passing to a shader as a sampl...
Phaser v3.18.1
Bug Fixes
InputManager.preRender
didn't get thetime
property correctly, causing input plugin methods that relied on it to fail.KeyboardPlugin.time
wasn't being set to the correct value, causingcheckDown
to fail constantly.