Phaser/phaser: Release v3.50.0-beta.2
Name: phaser
Owner: Phaser
Release: Phaser v3.50.0 Beta 2
Released: 2020-08-21
License: MIT
Release Assets:
WebGL Pipeline Updates
If you use a custom WebGL Pipeline in your game, you must update in order to use Phaser 3.50.
Due to the huge amount of work that has taken place in this area, all of the pipelines have been renamed. If you extend any of these pipelines or use them in your game code (referenced by name), then please update accordingly. The name changes are:
TextureTintPipelineis now called theMultiPipeline.TextureTintStripPipelineis now called theRopePipeline.ForwardDiffuseLightPipelineis now called theLightPipeline.
To match the new pipeline names, the shader source code has also been renamed.
ForwardDiffuse.fragis now calledLight.frag.TextureTint.fragis now calledMulti.frag.TextureTint.vertis now calledMulti.vert.
Other pipeline changes are as follows:
Types.Renderer.WebGL.WebGLPipelineConfigis a new TypeDef that helps you easily configure your own Custom Pipeline when using TypeScript and also provides better JSDocs.Types.Renderer.WebGL.WebGLPipelineAttributesConfigis a new TypeDef that helps you easily configure the attributes for your own Custom Pipelines when using TypeScript and also provides better JSDocs.- All pipelines will now work out the
rendererproperty automatically, so it's no longer required in the config. - All pipelines will now work out the
glproperty automatically, so it's no longer required in the config. - All pipelines will now extract the
nameproperty from the config, allowing you to set it externally. - All pipelines will now extract the
vertexCapacityproperty from the config, allowing you to set it externally. - All pipelines will now extract the
vertexSizeproperty from the config, allowing you to set it externally. - All pipelines will now extract the
vertexDataproperty from the config, allowing you to set it externally. - All pipelines will now extract the
attributesproperty from the config, allowing you to set it externally. - All pipelines will now extract the
topologyproperty from the config, allowing you to set it externally.
Single Pipeline
There is also a new pipeline called SinglePipeline, created to emulate the old TextureTintPipeline. This special pipeline uses just a single texture and makes things a lot easier if you wish to create a custom pipeline, but not have to recode your shaders to work with multiple textures. Instead, just extend SinglePipeline, where-as before you extended the TextureTintPipeline and you won't have to change any of your shader code. However, if you can, you should update it to make it perform faster, but that choice is left up to you.
WebGL Multi-Texture Rendering
The Multi Pipeline (previously 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 draw call-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.maxTexturesis a new game config setting that allows you to control how many texture units will be used in WebGL.WebGL.Utils.checkShaderMaxis a new function, used internally by the renderer, to determine the maximum number of texture units the GPU + browser supports.- The property
WebGLRenderer.currentActiveTextureUnithas been renamed tocurrentActiveTexture. WebGLRenderer.startActiveTextureis a new read-only property contains the current starting active texture unit.WebGLRenderer.maxTexturesis a new read-only property that contains the maximum number of texture units WebGL can use.WebGLRenderer.textureIndexesis a new read-only array that contains all of the available WebGL texture units.WebGLRenderer.tempTexturesis a new read-only array that contains temporary WebGL textures.- The
WebGLRenderer.currentTexturesproperty has been removed, as it's no longer used. TextureSource.glIndexis a new property that holds the currently assigned texture unit for the Texture Source.TextureSource.glIndexCounteris a new property that holds the time the index was assigned to the Texture Source.WebGLRenderer.currentTextureshas been removed, as it's no longer used internally.WebGLRenderer.setBlankTextureno longer has aforceparameter, 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
inTexIdfloat attribute and dynamic generation. - The Texture Tint Pipeline has a new attribute,
inTexIdwhich is agl.FLOAT. TextureTintPipeline.bindis a new method that sets theuMainSampleruniform.- The
TextureTintPipeline.requireTextureBatchmethod has been removed, as it's no longer required. - The
TextureTintPipeline.pushBatchmethod has been removed, as it's no longer required. - The
TextureTintPipeline.maxQuadsproperty has been removed, as it's no longer required. - The
TextureTintPipeline.batchesproperty has been removed, as it's no longer required. TextureTintPipeline.flushhas been rewritten to support multi-textures.TextureTintPipeline.flushno longer creates a sub-array if the batch is full, but instead usesbufferDatafor speed.WebGLPipeline.currentUnitis a new property that holds the most recently assigned texture unit. Treat as read-only.WebGLRenderer.setTextureSourceis a new method, used by pipelines and Game Objects, that will assign a texture unit to the given Texture Source.- The
WebGLRenderer.setTexture2Dmethod has been updated to use the new texture unit assignment. It no longer takes thetextureUnitorflushparameters and these have been removed from its method signature. WebGLRenderer.setTextureZerois a new method that activates texture zero and binds the given texture to it. Useful for fbo backed game objects.WebGLRenderer.clearTextureZerois a new method that clears the texture that was bound to unit zero.WebGLRenderer.textureZerois a new property that holds the currently bound unit zero texture.WebGLRenderer.normalTextureis a new property that holds the currently bound normal map (texture unit one).WebGLRenderer.setNormalMapis a new method that sets the current normal map texture.WebGLRenderer.clearNormalMapis a new method that clears the current normal map texture.WebGLRenderer.resetTexturesis a new method that flushes the pipeline, resets all textures back to the temporary ones, and resets the active texture counter.WebGLPipeline.bootwill now check all of the attributes and store the pointer location within the attribute entry.WebGLPipeline.bindno 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.isNewNormalMapis a new method that returns a boolean if the given parameters are not currently used.WebGLPipeline.forceZerois a new property that informs Game Objects if the pipeline requires a zero bound texture unit.WebGLPipeline.setAttribPointersis a new method that will set the vertex attribute pointers for the pipeline.WebGLRenderer.unbindTexturesis a new method that will activate and then null bind all WebGL textures.Renderer.WebGL.Utils.parseFragmentShaderMaxTexturesis a new function that will take fragment shader source and search it for%count%and%forloop%declarations, replacing them with the required GLSL for multi-texture support, returning the modified source.
Light Pipeline Changes
The Light Pipeline (previously called the Forward Diffuse Light Pipeline), which is responsible for rendering lights under WebGL, has been rewritten to work with the new Multi Pipeline features. 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
Lightis dirty. - The pipeline will no longer reset all of the lights unless the quantity of lights has changed.
- The
ForwardDiffuseLightPipeline.defaultNormalMapproperty has changed, it's now an object with aglTextureproperty that maps to the pipelines default normal map. - The
ForwardDiffuseLightPipeline.bootmethod has been changed to now generate a default normal map. - The
ForwardDiffuseLightPipeline.onBindmethod has been removed as it's no longer required. - The
ForwardDiffuseLightPipeline.setNormalMapmethod has been removed as it's no longer required. ForwardDiffuseLightPipeline.bindis a new method that handles setting-up the shader uniforms.- The
ForwardDiffuseLightPipeline.batchTexturemethod has been rewritten to use the Texture Tint Pipeline function instead. - The
ForwardDiffuseLightPipeline.batchSpritemethod has been rewritten to use the Texture Tint Pipeline function instead. ForwardDiffuseLightPipeline.lightCountis a new property that stores the previous number of lights rendered.ForwardDiffuseLightPipeline.getNormalMapis a new method that will look-up and return a normal map for the given object.
Lights
Light.dirtyis a new property that controls if the light is dirty, or not, and needs its uniforms updating.Lighthas been recoded so that all of its properties are now setters that activate itsdirtyflag.LightsManager.destroywill now clear thelightPoolarray when destroyed, where-as previously it didn't.LightsManager.cullnow 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.MVPis a new namespace under which the Model View Projection functions now live.projIdentityis now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ProjectIdentityprojPerspis now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ProjectPerspectivemodelRotateXis now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.RotateXmodelRotateYis now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.RotateYmodelRotateZis now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.RotateZviewLoadis now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewLoadviewRotateXis now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewRotateXviewRotateYis now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewRotateYviewRotateZis now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewRotateZviewScaleis now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewScaleviewTranslateis now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewTranslatemodelIdentityis now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.IdentitymodelScaleis now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ScalemodelTranslateis now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.TranslateviewIdentityis now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewIdentityviewLoad2Dis now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewLoad2DprojOrthois now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ProjectOrthoPhaser.Renderer.WebGL.MVP.SetIdentityis a new function the others use, to save on space.
BitmapText New Features, Updates and API Changes
BitmapText.setCharacterTintis a new method that allows you to set a tint color (either additive or fill) on a specific range of characters within a static Bitmap Text. You can specify the start and length offsets and per-corner tint colors.BitmapText.setWordTintis a new method that allows you to set a tint color (either additive or fill) on all matching words within a static Bitmap Text. You can specify the word by string, or numeric offset, and the number of replacements to tint.BitmapText.setDropShadowis a new method that allows you to apply a drop shadow effect to a Bitmap Text object. You can set the horizontal and vertical offset of the shadow, as well as the color and alpha levels. Call this method with no parameters to clear a shadow.BitmapTextWebGLRendererhas been rewritten from scratch to make use of the new pre-cached WebGL uv texture and character location data generated byGetBitmapTextSize. This has reduced the number of calculations made in the function dramatically, as it no longer has work out glyph advancing or offsets during render, but only when the text content updates.BitmapText.getCharacterAtis a new method that will return the character data from the BitmapText at the givenxandycoordinates. The character data includes the code, position, dimensions, and glyph information.- The
BitmapTextSizeobject returned byBitmapText.getTextBoundshas a new property calledcharacterswhich is an array that contains the scaled position coordinates of each character in the BitmapText, which you could use for tasks such as determining which character in the BitmapText was clicked. ParseXMLBitmapFontwill now calculate the WebGL uv data for the glyphs during parsing. This avoids it having to be done during rendering, saving CPU cycles on an operation that never changes.ParseXMLBitmapFontwill now create a Frame object for each glyph. This means you could, for example, create a Sprite using the BitmapText texture and the glyph as the frame key, i.e.:this.add.sprite(x, y, fontName, 'A').BitmapTextWord,BitmapTextCharacterandBitmapTextLinesare three new type defs that are now part of theBitmapTextSizeconfig object, as returned bygetTextBounds. This improves the TypeScript defs and JS Docs for this object.- The signature of the
ParseXMLBitmapFontfunction has changed. Theframeparameter is no longer optional, and is now the second parameter in the list, instead of being the 4th. If you call this function directly, please update your code. - The
BitmapText.getTextBoundsmethod was being called every frame, even if the bounds didn't change, potentially costing a lot of CPU time depending on the text length and quantity of them. It now only updates the bounds if they change. - The
GetBitmapTextSizefunction usedMath.roundon the values, if theroundparameter wastrue, which didn't create integers. It now usesMath.ceilinstead to give integer results. - The
GetBitmapTextSizefunction has a new boolean parameterupdateOrigin, which will adjust the origin of the parent BitmapText if set, based on the new bounds calculations. BitmapText.preDestroyis a new method that will tidy-up all of the BitmapText data during object destruction.BitmapText.dropShadowXis a new property that controls the horizontal offset of the drop shadow on the Bitmap Text.BitmapText.dropShadowYis a new property that controls the vertical offset of the drop shadow on the Bitmap Text.BitmapText.dropShadowColoris a new property that sets the color of the Bitmap Text drop shadow.BitmapText.dropShadowAlphais a new property that sets the alpha of the Bitmap Text drop shadow.BatchCharis a new internal private function for batching a single character of a Bitmap Text to the pipeline.- If you give an invalid Bitmap Font key, the Bitmap Text object will now issue a
console.warn. - Setting the
colorvalue in theDynamicBitmapText.setDisplayCallbackwould inverse the red and blue channels if the color was not properly encoded for WebGL. It is now encoded automatically, meaning you can pass normal hex values as the colors in the display callback. Fix #5225 (thanks @teebarjunk) - If you apply
setSizeto the Dynamic BitmapText the scissor is now calculated based on the parent transforms, not just the local ones, meaning you can crop Bitmap Text objects that exist within Containers. Fix #4653 (thanks @lgibson02) ParseXMLBitmapFonthas a new optional parametertexture. If defined, this Texture is populated with Frame data, one frame per glyph. This happens automatically when loading Bitmap Text data in Phaser.
New Features
Geom.Intersects.GetLineToLineis a new function that will return a Vector3 containing the point of intersection between 2 line segments, with thezproperty holding the distance value.Geom.Intersects.GetLineToPolygonis a new function that checks for the closest point of intersection between a line segment and an array of polygons.Geom.Intersects.GetLineToPointsis a new function that checks for the closest point of intersection between a line segment and an array of points, where each pair of points form a line segment.Geom.Intersects.GetRaysFromPointToPolygonis a new function that emits rays out from the given point and detects for intersection against all given polygons, returning the points of intersection in the results array.Geom.Polygon.Translateis a new function that allows you to translate all the points of a polygon by the given values.Geom.Polygon.Simplifyis a new function that takes a polygon and simplifies the points by running them through a combination of Douglas-Peucker and Radial Distance algorithms, potentially dramatically reducing the number of points while retaining its shape.WebGLRenderer.setInt1ivwill allow you to look-up and set a 1iv uniform on the given shader.Phaser.Types.Math.Vector3Likeis a new data type representing as Vector 3 like object.Phaser.Types.Math.Vector4Likeis a new data type representing as Vector 4 like object.Transform.getLocalPointis a new method, available on all Game Objects, that takes anx/ypair and translates them into the local space of the Game Object, factoring in parent transforms and display origins.- The
KeyboardPluginwill now track the key code and timestamp of the previous key pressed and compare it to the current event. If they match, it will skip the event. On some systems, if you were to type quickly, you would sometimes get duplicate key events firing (the exact same event firing more than once). This is now prevented from happening. Display.Color.GetColorFromValueis a new function that will take a hex color value and return it as an integer, for use in WebGL. This is now used internally by the Tint component and other classes.Utils.String.RemoveAtis a new function that will remove a character from the given index in a string and return the new string.Frame.setUVsis a new method that allows you to directly set the canvas and UV data for a frame. Use this if you need to override the values set automatically during frame creation.TweenManager.getTweensOfhas a new parameterincludePending. If set, it will also check the pending tweens for the given targets and return those in the results as well. Fix #5260 (thanks @pcharest2000)WebGLPipeline.hasBootedis a new boolean property that tracks if the pipeline has been booted or not, which is now far more important in 3.5 than in previous versions. This is checked in theWebGLRenderer.addPipelinemethod, and if not set, the pipeline is booted. Fix #5251 #5255 (thanks @telinc1 @rexrainbow)- The WebGL Renderer will now add the pipelines during the
bootmethod, instead ofinit.
Updates and API Changes
- Earcut, used for polygon triangulation, has been updated from 2.1.4 to 2.2.2.
Config.batchSizehas been increased from 2000 to 4096.- Removed the Deferred Diffuse fragment and vertex shaders from the project, as they're not used.
StaticTilemapLayer.uploadwill now set the vertex attributes and buffer the data, and handles internal checks more efficiently.StaticTilemapLayernow includes theModelViewProjectionmixin, so it doesn't need to modify the pipeline during rendering.WebGLRenderer.textureFlushis a new property that keeps track of the total texture flushes per frame.- The
TextureTintStripPipelinenow extendsTextureTintPipelineand just changes the topolgy, vastly reducing the filesize. TransformMatrix.getXRoundis a new method that will return the X component, optionally passed viaMath.round.TransformMatrix.getYRoundis a new method that will return the Y component, optionally passed viaMath.round.- The
KeyboardPluginno longer emitskeydown_events. These were replaced withkeydown-events in v3.15. The previous event string was deprecated in v3.20. - The
KeyboardPluginno longer emitskeyup_events. These were replaced withkeyup-events in v3.15. The previous event string was deprecated in v3.20. - The
ScaleManager.updateBoundsmethod is now called every time the browser fires a 'resize' or 'orientationchange' event. This will update the offset of the canvas element Phaser is rendering to, which is responsible for keeping input positions correct. However, if you change the canvas position, or visibility, via any other method (i.e. via an Angular route) you should call theupdateBoundsmethod directly, yourself. - The constant
Phaser.Renderer.WebGL.BYTEvalue has been removed as it wasn't used internally. - The constant
Phaser.Renderer.WebGL.SHORTvalue has been removed as it wasn't used internally. - The constant
Phaser.Renderer.WebGL.UNSIGNED_BYTEvalue has been removed as it wasn't used internally. - The constant
Phaser.Renderer.WebGL.UNSIGNED_SHORTvalue has been removed as it wasn't used internally. - The constant
Phaser.Renderer.WebGL.FLOATvalue has been removed as it wasn't used internally.
Bug Fixes
RenderTexture.resize(which is called fromsetSize) wouldn't correctly set theTextureSource.glTextureproperty, leading tobindTexture: attempt to use a deleted objecterrors under WebGL.RenderTexture.fillwould fail to fill the correct area under WebGL if the RenderTexture wasn't the same size as the Canvas. It now fills the given region properly.- The
MatterAttractorsplugin, which enables attractors between bodies, has been fixed. The original plugin only worked if the body with the attractor was first in the world bodies list. It can now attract any body, no matter where in the world list it is. Fix #5160 (thanks @strahius) - The
KeyboardManagerandKeyboardPluginwere both still checking for theInputManager.useQueueproperty, which was removed several versions ago. - In Arcade Physics, Dynamic bodies would no longer hit walls when riding on horizontally moving platforms. The horizontal (and vertical) friction is now re-applied correctly in these edge-cases. Fix #5210 (thanks @Dercetech @samme)
- Calling
Rectangle.setSize()wouldn't change the underlying geometry of the Shape Game Object, causing any stroke to be incorrectly rendered after a size change. - The
ProcessQueuewas emitting the wrong events internally. It now emits 'add' and 'remove' correctly (thanks @halilcakar)
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 @16patsle @scott20145 @khasanovbi @mk360