UNPKG

phaser

Version:

A fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers.

457 lines (365 loc) 183 kB
## Version 3.53.1 - Anastasia - 8th March 2021 * Fixed an issue where Container children were not removed from the display list properly. ## Version 3.53.0 - Anastasia - 8th March 2021 ### New Features * You can now run Phaser from within a Web Worker. You must use the `type: 'classic'` method and then use `importScripts('phaser.js')` within your workers, but it will no longer throw window errors and allows you access to lots of the core Phaser functions from Workers. * `Scenes.Events.PRE_RENDER` is a new event fired after the display list is sorted and before the Scene is rendered (thanks @samme) * You can now set the boolean `preserveDrawingBuffer` in the Game Config (either directly, or in the Render Config). This is passed to the WebGL context during creation and controls if the buffers are automatically cleared each frame or not. The default is to clear them. Set to `true` to retain them. * `GameObjects.Shape.setDisplaySize` is a new method that helps setting the display width and height of a Shape object in a chainable way. Fix #5526 (thanks @samme) * `Tilemaps.Parsers.Tiled.ParseTilesets` has been updated so it now retains the `type` field information that can be optionally specified within Tiled. This is useful when creating objects from tiles and tile variants (thanks @lackhand) * `Tilemaps.Parsers.Tiled.ParseWangsets` is a new function that will parse the Wangset information from Tiled map data, if present, and retain it so you can access the data (thanks @lackhand) * `WebGLPipeline.glReset` is a new boolean property that keeps track of when the GL Context was last reset by the Pipeline Manager. It then redirects calls to `bind` to `rebind` instead to restore the pipeline state. ### Display List Updates * `GameObject.addToDisplayList` is a new method that allows you to add a Game Object to the given Display List. If no Display List is given, it will default to the Scene Display List. A Game Object can only exist on one Display List at any given time, but may move freely between them. * `GameObject.addToUpdateList` is a new method that adds the Game Object to the Update List belonging to the Scene. When a Game Object is added to the Update List it will have its `preUpdate` method called every game frame. * `GameObject.removeFromDisplayList` is a new method that removes the Game Object from the Display List it is currently on. * `GameObject.removeFromUpdateList` is a new method that removes the Game Object from the Scenes Update List. * `GameObject.destroy` will now call the new `removeFromDisplayList` and `removeFromUpdateList` methods. * `DisplayList.addChildCallback` will now use the new `addToDisplayList` and `removeFromDisplayList` Game Object methods. * `Container.addHandler` will now use the new `addToDisplayList` and `removeFromDisplayList` Game Object methods. * `Layer.addChildCallback` and `removeChildCallback` will now use the new `addToDisplayList` and `removeFromDisplayList` Game Object methods. * `Group` now listens for the `ADDED_TO_SCENE` and `REMOVED_FROM_SCENE` methods and adds and removes itself from the Update List accordingly. * `Group.add` and `create` now uses the new `addToDisplayList` and `addToUpdateList` Game Object methods. * `Group.remove` now uses the new `removeFromDisplayList` and `removeFromUpdateList` Game Object methods. * `Group.destroy` has a new optional boolean parameter `removeFromScene`, which will remove all Group children from the Scene if specified. ### Updates * Phaser no longer includes the IE9 polyfills. All polyfills have been removed from the core builds and moved to their own specific version called `phaser-ie9`, which can be found in the `dist` folder. * All of the Device functions will now check to see if Phaser is running inside of a Web Worker, or not. If it is, they will return early, avoiding trying to make calls to `window` or other elements not present within Workers. * The Webpack loaders have been moved to dev dependencies to avoid peer issues during use of Phaser as a package (thanks @andrewstart) * The `WebAudioSoundManager.createAudioContext` method is no longer private. * The `WebAudioSoundManager.context` property is no longer private. * The `WebAudioSoundManager.masterMuteNode` property is no longer private. * The `WebAudioSoundManager.masterVolumeNode` property is no longer private. * The `WebAudioSoundManager.destination` property is no longer private. * The `WebAudioSound.audioBuffer` property is no longer private. * The `WebAudioSound.source` property is no longer private. * The `WebAudioSound.loopSource` property is no longer private. * The `WebAudioSound.muteNode` property is no longer private. * The `WebAudioSound.volumeNode` property is no longer private. * The `WebAudioSound.pannerNode` property is no longer private. * The `WebAudioSound.hasEnded` property is no longer private, but _is_ read only. * The `WebAudioSound.hasLooped` property is no longer private, but _is_ read only. * The `WebAudioSoundManager.createAudioContext` method will now use `webkitAudioContext` if defined in `window` (rather than using the polyfill) to handle audio on Safari. * If a loaded JSON File fails to parse it will now issue a console warning along with the file key (thanks @samme) * The Canvas Renderer will no longer run a `fillRect` if `clearBeforeRender` is `false` in the Game Config. * The `LightsManager.addPointlight` method now has full JSDocs and the `attenuation` parameter. * `LightPipeline.lightsActive` is a new boolean property that keeps track if the Lights Manager in a Scene is active, or not. * The `LightPipeline` now only calls `batchSprite`, `batchTexture` and `batchTextureFrame` if the Scene Lights Manager is active. Fix #5522 (thanks @inmylo) * The Tiled Parser has been updated so it now supports object properties defined in an array with name / type values (thanks @veleek) * `LineCurve.getTangent` can now take an output vector to receive the tangent value (thanks @samme) * `DOMElementCSSRenderer` no longer sets the `pointerEvents` style attribute to `auto`. This is the default value anyway and it now means you can override it from your code by setting the `pointer-events` attribute directly. Fix #5470 (thanks @hayatae @endel) * `SceneManager.loadComplete` will no longer try to unlock the Sound Manager, preventing `AudioContext was not allowed to start` console warnings after each Scene finishes loading. * `WebGLRenderer.deleteTexture` will now run `resetTextures(true)` first, incase the requested texture to be deleted is currently bound. Previously, it would delete the texture and then reset them. * If `TextureSource.destroy` has a WebGL Texture it will tell the WebGL Renderer to reset the textures first, before deleting its texture. * `Cameras.Controls.FixedKeyControl.minZoom` is a new configurable property that sets the minimum camera zoom. Default to 0.001 (thanks @samme) * `Cameras.Controls.FixedKeyControl.maxZoom` is a new configurable property that sets the maximum camera zoom. Default to 1000 (thanks @samme) * `Cameras.Controls.SmoothedKeyControl.minZoom` is a new configurable property that sets the minimum camera zoom. Default to 0.001 (thanks @samme) * `Cameras.Controls.SmoothedKeyControl.maxZoom` is a new configurable property that sets the maximum camera zoom. Default to 1000 (thanks @samme) * The `WebGLPipeline.rebind` method now accepts an optional parameter `currentShader`. If provided it will set the current shader to be this after the pipeline reset is complete. * The `PipelineManager.rebind` method will now flag all pipelines as `glReset = true`, so they know to fully rebind the next time they are invoked. ### Bug Fixes * `BlitterWebGLRenderer` was calling an out-dated function `setRenderDepth` instead of `addToRenderList` (thanks Harm) * When a loaded JSON file fails to parse, it's marked `FILE_ERRORED` and the Loader continues. Before this change the Loader would stall (thanks @samme) * `Math.FromPercent` silently assumed the `min` parameter to be 0. It can now be any value, allowing you to generate percentages between `min` and `max` correctly (thanks @somechris) * The Container and Zone Game Objects were not handling being added to the render list, causing them to fail input detection tests. Fix #5506 #5508 (thanks @rexrainbow @vforsh @Nightspeller) * `IsometricWorldToTileXY` was returning a tile incorrectly offset from the given coordinates. It now returns from the expected location (thanks @veleek) * `DOMElementCSSRenderer` will now return early if `src.node` doesn't exist or is null, rather than trying to extract the `style` property from it. Fix #5566 (thanks @rattias) * The BitmapMask will now check to see if `renderer` exists before trying to hook to its event emitter (thanks @mattjennings) * TileSprite will now check to see if `renderer` exists before trying to restore itself during a context loss (thanks @mattjennings) * A Texture will now check to see if `renderer` exists before resetting the WebGL textures (thanks @mattjennings) * Destroying a Text Game Object when using the HEADLESS renderer would cause an `Uncaught TypeError`. Fix #5558 (thanks @mattjennings) * The `Actions.PlayAnimation` arguments have been updated to match the new animation system introduced in Phaser 3.50. It will now take either a string-key, or a play animation configuration object, and the `startFrame` parameter has been replaced with `ignoreIfPlaying`. The function will also only call `play` if the Game Object has an animation component, meaning you can now supply this action with a mixed-content array without errors. Fix #5555 (thanks @xuxucode) * `RenderTarget.resize` will now `Math.floor` the scaled width and height as well as ensure they're not <= 0 which causes `Framebuffer status: Incomplete Attachment` errors. Fix #5563 #5478 (thanks @orjandh @venarius) * `Matter.Components.Sleep.setToSleep` and `setAwake` were documented as returning `this`, however they didn't return anything. Both now `return this` correctly. Fix #5567 (thanks @micsun-al) * The Particle position would be wrong when set to follow a Sprite using the Canvas Renderer. Fix #5457 (thanks @samme) * Fixed a conditional bug in Arcade Physics `ProcessX` when Body2 is Immovable and Body1 is not. * The Spine Plugin would throw an error while unloading and restarting the game. Fix #5477 (thanks @ayamomiji @Pong420) * The Spine Plugin would cause all textures to render as blue if a Spine object followed any Game Object using the Graphics Pipeline on the display list, due to the gl context restoration not being properly handled. Fix #5493 #5449 (thanks @EmilSV @FloodGames) * Spine Game Objects and Containers will now add themselves to the Camera render list, fixing issues where input didn't work if depth was used or they were overlapped with another interactive Game Object. * Calling `Group.destroy` would cause a runtime error if `Group.runChildUpdate` had been set. Fix #5576 (thanks @samme) * Moving a Sprite from a Container or Layer to the Scene would fail without first resetting the display list. Fix #5535 (thanks @malahaas @samme @tringcooler) ### 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: @edemaine @xuxucode @schontz @kaktus42 @Nero0 @samme ## Version 3.52.0 - Crusch - 14th January 2021 ### New Features * The `getPostPipeline` method available on most Game Objects will now return an array of piplines if an instance is given and the Game Object has more than one of those pipelines set on it. If only one pipeline is set, it will be returned directly. ### Updates * `BaseCamera.renderList` is a new array that is populated with all Game Objects that the camera has rendered in the current frame. It is automatically cleared during `Camera.preUpdate` and is an accurate representation of the Game Objects the Camera rendered. It's used internally by the Input Plugin, but exposed should you wish to read the contents or use it for profiling. * `BaseCamera.addToRenderList` is a new method that will add the given Game Object to the Cameras current render list. * The `InputPlugin.sortGameObjects` method now uses the new Camera render list to work out the display index depths. * The `InputPlugin.sortDropZones` method is a new method, based on the old `sortGameObjects` method that is used for sorting input enabled drop zones. * The background color behind the game url in the banner is now transparent, so it looks correct with dark dev tools themes (thanks @kainage) ### Bug Fixes * `WebAudioSound.destroy` now checks to see if `pannerNode` exists before disabling it, preventing an error in Safari (thanks @jdcook) * Fixed the cause of `Uncaught TypeError: Cannot read property 'getIndex' of null` by checking the display list property securely. Fix #5489 (thanks @actionmoon) * Fixed an issue where adding input-enabled Game Objects to a Layer would have the input system ignore their depth settings. Fix #5483 (thanks @pr4xx) * The method `TilemapLayer.weightedRandomize` has changed so that the parameter `weightedIndexes` is now first in the method and is non-optional. Previously, it was the 5th parameter and incorrectly flagged as optional. This change was made to the docs but not the parameters, but now works according to the docs (thanks Fantasix) * The Mesh `GenerateVerts` function was returning an object with the property `verts` instead of `vertices` as expected by the `Mesh.addVertices` method. It now returns the correct name (thanks @lackhand) * `AtlasJSONFile` will now call `File.pendingDestroy`, clearing up the resources it used during load and emitting a missing `FILE_COMPLETE` event. Fix #5495 (thanks @mikuso) * `AtlasJSONFile`, `AtlasXMLFile`, `BitmapFontFile` and `UnityAtlasFile` will now call `File.pendingDestroy`, clearing up the resources it used during load and emiting a missing `FILE_COMPLETE` event. Fix #5495 (thanks @mikuso) * Some Bitmap Text fonts were not rendering under Canvas due to the way in which the texture offset was calculated. It now uses the `__BASE` frame to get the texture offset, rather than the first frame in the set. Fix #5462 #5501 (thanks @monteiz @DPMakerQB) ### 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: @ygongdev Tucker @lackhand ## Version 3.51.0 - Emilia - 5th January 2021 ### New Features * `WebGLRenderer.isTextureClean` is a new boolean property that tracks of all of the multi-textures are in a clean 'default' state, to avoid lots of gl texture binds and activations during a Scene restart or destruction process. * `GameObject.removePostPipeline` would previously only remove a single pipeline instance. Calling the method with a class will now clear all instances of the pipeline class from the Game Object (thanks @rexrainbow) ### Updates * `Layer.destroy` will now call `destroy` on all of its children as well. * The `Layer` Game Object has been given all of the missing properties and methods from Game Object to make the class shapes identical. This includes the properties `parentContainer`, `tabIndex`, `input` and `body`. You cannot set any of these properties, they are ignored by the Layer itself. It also includes the methods: `setInteractive`, `disableInteractive` and `removeInteractive`. A Layer cannot be enabled for input or have a physics body. Fix #5459 (thanks @PhaserEditor2D) * `Layer.getIndexList` is a new method, taken from the Game Object, that will return the index of the Layer in the display list, factoring in any parents. ### Bug Fixes * On some keyboards it was possible for the `keyup` event to not fire because it was filtered out by the Keyboard Plugin repeat key check. Fix #5472 (thanks @cjw6k) * Fixed issue causing `Cannot read property 'pipelines' of null` to be thrown if using 3.50 with the HEADLESS renderer. Fix #5468 (thanks @Grenagar) * Canvas Tilemap Rendering is now working again. Fix #5480 (thanks @marshmn) * `Layer.destroy` will now emit the `DESTROY` event at the start of the method. Fix #5466 (thanks @samme) * The error `RENDER WARNING: there is no texture bound to the unit ...` would be thrown when trying to restart a Scene. When a Scene is shutdown is will now reset the WebGL Texture cache. Fix #5464 (thanks @ffx0s) * The error `RENDER WARNING: there is no texture bound to the unit ...` would be thrown when destroying a Text Game Object, or any Game Object that uses its own custom texture. Destroying such an object will now reset the WebGL Texture cache. Fix #5464 (thanks @mark-rushakoff) * When using an asset pack with a prefix, and loading a Spine file, the prefix was being appended twice causing the texture to fail loading. It's now appended correctly (thanks @jdcook) ### 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: @pol0nium @ErinLMoore @umi-tyaahan @nk9 ## Version 3.50.1 - Subaru - 21st December 2020 * The new Web Audio Panning feature breaks WebAudio on Safari (OSX and iOS). The stero panner node is now only created if supported. Fix #5460 (thanks @d4rkforce) ## Version 3.50.0 - Subaru - 16th December 2020 Due to the massive amount of changes in 3.50 this Change Log is, by its nature, very long. It's important to scan through it, especially if you're porting a game from an earlier version of Phaser to 3.50. However, if you're after more top-level descriptions of what's new, with example code, then please see the posts we will be making to the Phaser site and Phaser Patreon in the coming months after release. We have also updated the Phaser 3 Examples site, so that every single example up there has been rewritten for 3.50, so you don't have to struggle working through old or deprecated syntax. Virtually all new features are covered in new examples, as well. With that said, we've tried to organize the Change Log into commonly themed sections to make it more digestible, but we appreciate there is a lot here. Please don't feel overwhelmed! If you need clarification about something, join us on the Phaser Discord and feel free to ask. ### WebGL Pipelines and Post Processing WebGL Pipelines are responsible for the rendering of all Game Objects in Phaser and they have had a complete rewrite in 3.50. This was to allow for the introduction of post processing pipelines, now readily available to be created from the new Post FX Pipeline class. The changes in this area have been extensive, so if you use custom WebGL Pipelines in your game already, you must update your code to use Phaser 3.50. #### Pipeline Manager The `WebGL.PipelineManager` is a new class that is responsible for managing all of the WebGL Pipelines in Phaser. An instance of the Pipeline Manager is created by the WebGL Renderer and is available under the `pipelines` property. This means that the WebGL Renderer no longer handles pipelines directly, causing the following API changes: * `WebGLRenderer.pipelines` is no longer a plain object containing pipeline instances. It's now an instance of the `PipelineManager` class. This instance is created during the init and boot phase of the renderer. * The `WebGLRenderer.currentPipeline` property no longer exists, instead use `PipelineManager.current`. * The `WebGLRenderer.previousPipeline` property no longer exists, instead use `PipelineManager.previous`. * The `WebGLRenderer.hasPipeline` method no longer exists, instead use `PipelineManager.has`. * The `WebGLRenderer.getPipeline` method no longer exists, instead use `PipelineManager.get`. * The `WebGLRenderer.removePipeline` method no longer exists, instead use `PipelineManager.remove`. * The `WebGLRenderer.addPipeline` method no longer exists, instead use `PipelineManager.add`. * The `WebGLRenderer.setPipeline` method no longer exists, instead use `PipelineManager.set`. * The `WebGLRenderer.rebindPipeline` method no longer exists, instead use `PipelineManager.rebind`. * The `WebGLRenderer.clearPipeline` method no longer exists, instead use `PipelineManager.clear`. The Pipeline Manager also offers the following new features: * The `PipelineManager.resize` method automatically handles resize events across all pipelines. * The `PipelineManager.preRender` method calls the pre-render method of all pipelines. * The `PipelineManager.render` method calls the render method of all pipelines. * The `PipelineManager.postRender` method calls the post-render method of all pipelines. * The `PipelineManager.setMulti` method automatically binds the Multi Texture Pipeline, Phasers default. * The `PipelineManager.clear` method will clear the pipeline, store it in `previous` and free the renderer. * The `PipelineManager.rebind` method will reset the rendering context and restore the `previous` pipeline, if set. * The `PipelineManager.copyFrame` method will copy a `source` Render Target to the `target` Render Target, optionally setting the brightness of the copy. * The `PipelineManager.blitFrame` method will copy a `source` Render Target to the `target` Render Target. Unlike `copyFrame` no resizing takes place and you can optionally set the brightness and erase mode of the copy. * The `PipelineManager.copyFrameRect` method binds the `source` Render Target and then copies a section of it to the `target` using `gl.copyTexSubImage2D` rather than a shader, making it much faster if you don't need blending or preserving alpha details. * The `PipelineManager.copyToGame` method pops the framebuffer from the renderers FBO stack and sets that as the active target, then draws the `source` Render Target to it. Use when you need to render the _final_ result to the game canvas. * The `PipelineManager.drawFrame` method will copy a `source` Render Target, optionally to a `target` Render Target, using the given ColorMatrix, allowing for full control over the luminance values used during the copy. * The `PipelineManager.blendFrames` method draws the `source1` and `source2` Render Targets to the `target` Render Target using a linear blend effect, which is controlled by the `strength` parameter. * The `PipelineManager.blendFramesAdditive` method draws the `source1` and `source2` Render Targets to the `target` Render Target using an additive blend effect, which is controlled by the `strength` parameter. * The `PipelineManager.clearFrame` method clears the given Render Target. New constants have been created to help you reference a pipeline without needing to use strings: * `Phaser.Renderer.WebGL.Pipelines.BITMAPMASK_PIPELINE` for the Bitmap Mask Pipeline. * `Phaser.Renderer.WebGL.Pipelines.LIGHT_PIPELINE` for the Light 2D Pipeline. * `Phaser.Renderer.WebGL.Pipelines.SINGLE_PIPELINE` for the Single Pipeline. * `Phaser.Renderer.WebGL.Pipelines.MULTI_PIPELINE` for the Multi Pipeline. * `Phaser.Renderer.WebGL.Pipelines.ROPE_PIPELINE` for the Rope Pipeline. * `Phaser.Renderer.WebGL.Pipelines.POINTLIGHT_PIPELINE` for the Point Light Pipeline. * `Phaser.Renderer.WebGL.Pipelines.POSTFX_PIPELINE` for the Post FX Pipeline. * `Phaser.Renderer.WebGL.Pipelines.UTILITY_PIPELINE` for the Utility Pipeline. All Game Objects have been updated to use the new constants and Pipeline Manager. #### Post FX Pipeline The Post FX Pipeline is a brand new and special kind of pipeline specifically for handling post processing effects in Phaser 3.50. Where-as a standard Pipeline allows you to control the process of rendering Game Objects by configuring the shaders and attributes used to draw them, a Post FX Pipeline is designed to allow you to apply processing _after_ the Game Object/s have been rendered. Typical examples of post processing effects are bloom filters, blurs, light effects and color manipulation. The pipeline works by creating a tiny vertex buffer with just one single hard-coded quad in it. Game Objects can have a Post Pipeline set on them, which becomes their own unique pipeline instance. Those objects are then rendered using their standard pipeline, but are redirected to the Render Targets owned by the post pipeline, which can then apply their own shaders and effects, before passing them back to the main renderer. The following properties and methods are available in the new `PostFXPipeline` class: * The `PostFXPipeline.gameObject` property is a reference to the Game Object that owns the Post Pipeline, if any. * The `PostFXPipeline.colorMatrix` property is a Color Matrix instance used by the draw shader. * The `PostFXPipeline.fullFrame1` property is a reference to the `fullFrame1` Render Target that belongs to the Utility Pipeline, as it's commonly used in post processing. * The `PostFXPipeline.fullFrame2` property is a reference to the `fullFrame2` Render Target that belongs to the Utility Pipeline, as it's commonly used in post processing. * The `PostFXPipeline.halfFrame1` property is a reference to the `halfFrame1` Render Target that belongs to the Utility Pipeline, as it's commonly used in post processing. * The `PostFXPipeline.halfFrame2` property is a reference to the `halfFrame2` Render Target that belongs to the Utility Pipeline, as it's commonly used in post processing. * The `PostFXPipeline.copyFrame` method will copy a `source` Render Target to the `target` Render Target, optionally setting the brightness of the copy. * The `PostFXPipeline.blitFrame` method will copy a `source` Render Target to the `target` Render Target. Unlike `copyFrame` no resizing takes place and you can optionally set the brightness and erase mode of the copy. * The `PostFXPipeline.copyFrameRect` method binds the `source` Render Target and then copies a section of it to the `target` using `gl.copyTexSubImage2D` rather than a shader, making it much faster if you don't need blending or preserving alpha details. * The `PostFXPipeline.copyToGame` method pops the framebuffer from the renderers FBO stack and sets that as the active target, then draws the `source` Render Target to it. Use when you need to render the _final_ result to the game canvas. * The `PostFXPipeline.drawFrame` method will copy a `source` Render Target, optionally to a `target` Render Target, using the given ColorMatrix, allowing for full control over the luminance values used during the copy. * The `PostFXPipeline.blendFrames` method draws the `source1` and `source2` Render Targets to the `target` Render Target using a linear blend effect, which is controlled by the `strength` parameter. * The `PostFXPipeline.blendFramesAdditive` method draws the `source1` and `source2` Render Targets to the `target` Render Target using an additive blend effect, which is controlled by the `strength` parameter. * The `PostFXPipeline.clearFrame` method clears the given Render Target. * The `PostFXPipeline.bindAndDraw` method binds this pipeline and draws the `source` Render Target to the `target` Render Target. This is typically the final step taken in when post processing. #### Renamed WebGL Pipelines 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: * `TextureTintPipeline` is now called the `MultiPipeline`. * `TextureTintStripPipeline` is now called the `RopePipeline`. * `ForwardDiffuseLightPipeline` is now called the `LightPipeline`. There is also the new `GraphicsPipeline`. Previously, the `TextureTintPipeline` was responsible for rendering all Sprites, Graphics, and Shape objects. Now, it only renders Sprites. All Graphics and Shapes are handled by the new `GraphicsPipeline`, which uses its own shaders. See below for details about this change. To match the new pipeline names, the shader source code has also been renamed. * `ForwardDiffuse.frag` is now called `Light.frag`. * `TextureTint.frag` is now called `Multi.frag`. * `TextureTint.vert` is now called `Multi.vert`. #### WebGL Pipelines Updates Further pipeline changes are as follows: * None of the shaders or pipelines use the `uViewMatrix` and `uModelMatrix` uniforms any longer. These were always just plain identity matrices, so there is no point spending CPU and GPU time to set them as uniforms or use them in the shaders. Should you need these uniforms, you can add them to your own custom pipelines. * `Types.Renderer.WebGL.WebGLPipelineConfig` is a new TypeDef that helps you easily configure your own Custom Pipeline when using TypeScript and also provides better JSDocs. * `Types.Renderer.WebGL.WebGLPipelineAttributesConfig` is 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 `renderer` property automatically, so it's no longer required in the config. * All pipelines will now work out the `gl` property automatically, so it's no longer required in the config. * All pipelines will now extract the `name` property from the config, allowing you to set it externally. * All pipelines will now extract the `vertexCapacity` property from the config, allowing you to set it externally. * All pipelines will now extract the `vertexSize` property from the config, allowing you to set it externally. * All pipelines will now extract the `vertexData` property from the config, allowing you to set it externally. * All pipelines will now extract the `attributes` property from the config, allowing you to set it externally. * All pipelines will now extract the `topology` property from the config, allowing you to set it externally. * The `WebGLPipeline.shouldFlush` method now accepts an optional parameter `amount`. If given, it will return `true` if the amount to be added to the vertex count exceeds the vertex capacity. The Multi Pipeline has been updated to now use this method instead of performing the comparison multiple times itself. * The `RopePipeline` now extends `MultiPipeline` and just changes the topology, vastly reducing the file size. * The `WebGLPipeline.flushLocked` property has been removed. A pipeline can never flush in the middle of a flush anyway, so it was just wasting CPU cycles being set. * `WebGLPipeline.manager` is a new property that is a reference to the WebGL Pipeline Manager. * `WebGLPipeline.currentUnit` is a new property that holds the most recently assigned texture unit. Treat as read-only. * `WebGLPipeline.forceZero` is a new boolean property that sets if the pipeline should force the use of texture zero. * `WebGLPipeline.hasBooted` is a new boolean property that is set once the pipeline has finished setting itself up and has booted. * `WebGLPipeline.isPostFX` is a new boolean property that is only set by Post FX Pipelines to help identify them. * `WebGLPipeline.renderTargets` is a new property that holds an array of WebGL Render Targets belonging to the pipeline. * `WebGLPipeline.currentRenderTarget` is a new property that holds a reference to the currently bound Render Target. * `WebGLPipeline.shaders` is a new property that holds an array of all WebGLShader instances that belong to the pipeline. * `WebGLPipeline.currentShader` is a new property that holds a reference to the currently active shader within the pipeline. * `WebGLPipeline.config` is a new property that holds the pipeline configuration object used to create it. * `WebGLPipeline.projectionMatrix` is a new property that holds a Matrix4 used as the projection matrix for the pipeline. * `WebGLPipeline.setProjectionMatrix` is a new method that allows you to set the ortho projection matrix of the pipeline. * `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. * `WebGLPipeline.setAttribPointers` is a new method that will set the vertex attribute pointers for the pipeline. * `WebGLPipeline.setShader` is a new method that allows you to set the currently active shader within the pipeline. * `WebGLPipeline.getShaderByName` is a new method that allows you to get a shader from the pipeline based on its name. * `WebGLPipeline.setShadersFromConfig` is a new method that destroys all current shaders and creates brand new ones parsed from the given config object. This is part of the pipeline boot process, but also exposed should you need to call it directly. * `WebGLPipeline.setGameObject` is a new method that custom pipelines can use in order to perform pre-batch tasks for the given Game Object. * `WebGLPipeline.setVertexBuffer` is a new method that checks if the pipelines vertex buffer is active, or not, and if not, binds it as the active buffer. This used to be performed by the WebGL Renderer, but pipelines now manage this directly. * `WebGLPipeline.preBatch` is a new method that is called when a new quad is about to be added to the batch. This is used by Post FX Pipelines to set frame buffers. * `WebGLPipeline.postBatch` is a new method that is called after a quad has been added to the batch. This is used by Post FX Pipelines to apply post processing. * `WebGLPipeline.unbind` is a new method that unbinds the current Render Target, if one is set. * `WebGLPipeline.batchVert` is a new method that adds a single vertex to the vertex buffer and increments the count by 1. * `WebGLPipeline.batchQuad` is a new method that adds a single quad (6 vertices) to the vertex buffer and increments the count, flushing first if adding the quad would exceed the batch limit. * `WebGLPipeline.batchTri` is a new method that adds a single tri (3 vertices) to the vertex buffer and increments the count, flushing first if adding the tri would exceed the batch limit. * `WebGLPipeline.drawFillRect` is a new method that pushes a filled rectangle into the vertex batch. * `WebGLPipeline.setTexture2D` is a new method that sets the texture to be bound to the next available texture unit. * `WebGLPipeline.bindTexture` is a new method that immediately activates the given WebGL Texture and binds it to the requested slot. * `WebGLPipeline.bindRenderTarget` is a new method that binds the given Render Target to a given texture slot. * `WebGLPipeline.setTime` is a new method that gets the current game loop duration to the given shader uniform. #### Pipeline Hooks The `WebGLPipeline` class has lots of new hooks you can use. These are all empty by default so you can safely override them in your own classes to take advantage of them: * `WebGLPipeline.onBoot` is a new hook you can override in your own pipelines that is called when the pipeline has booted. * `WebGLPipeline.onResize` is a new hook you can override in your own pipelines that is called when the pipeline is resized. * `WebGLPipeline.onDraw` is a new hook you can override in your own pipelines that is called by Post FX Pipelines every time `postBatch` is invoked. * `WebGLPipeline.onActive` is a new hook you can override in your own pipelines that is called every time the Pipeline Manager makes the pipeline the active pipeline. * `WebGLPipeline.onBind` is a new hook you can override in your own pipelines that is called every time a Game Object asks the Pipeline Manager to use this pipeline, even if it's already active. * `WebGLPipeline.onRebind` is a new hook you can override in your own pipelines that is called every time the Pipeline Manager needs to reset and rebind the current pipeline. * `WebGLPipeline.onBatch` is a new hook you can override in your own pipelines that is called _after_ a new quad (or tri) has been added to the batch. * `WebGLPipeline.onPreBatch` is a new hook you can override in your own pipelines that is called _before_ a new Game Object is about to process itself through the batch. * `WebGLPipeline.onPostBatch` is a new hook you can override in your own pipelines that is called _after_ a new Game Object has added itself to the batch. * `WebGLPipeline.onPreRender` is a new hook you can override in your own pipelines that is called once, per frame, right before anything has been rendered. * `WebGLPipeline.onRender` is a new hook you can override in your own pipelines that is called once, per frame, by every Camera in the Scene that wants to render, at the start of the render process. * `WebGLPipeline.onPostRender` is a new hook you can override in your own pipelines that is called once, per frame, after all rendering has happened and snapshots have been taken. * `WebGLPipeline.onBeforeFlush` is a new hook you can override in your own pipelines that is called immediately before the `gl.bufferData` and `gl.drawArrays` calls are made, so you can perform any final pre-render modifications. * `WebGLPipeline.onAfterFlush` is a new hook you can override in your own pipelines that is called after `gl.drawArrays`, so you can perform additional post-render effects. #### Pipeline Events The `WebGLPipeline` class now extends the Event Emitter and emits the following new events: * The `WebGL.Pipelines.Events.AFTER_FLUSH` event is dispatched by a WebGL Pipeline right after it has issued a `drawArrays` command. * The `WebGL.Pipelines.Events.BEFORE_FLUSH` event is dispatched by a WebGL Pipeline right before it is about to flush. * The `WebGL.Pipelines.Events.BIND` event is dispatched by a WebGL Pipeline when it is bound by the Pipeline Manager. * The `WebGL.Pipelines.Events.BOOT` event is dispatched by a WebGL Pipeline when it has finished booting. * The `WebGL.Pipelines.Events.DESTROY` event is dispatched by a WebGL Pipeline when it begins its destruction process. * The `WebGL.Pipelines.Events.REBIND` event is dispatched by a WebGL Pipeline when the Pipeline Manager resets and rebinds it. * The `WebGL.Pipelines.Events.RESIZE` event is dispatched by a WebGL Pipeline when it is resized, usually as a result of the Renderer. #### Pipeline Uniform Changes WebGLShaders have a `uniforms` object that is automatically populated when the shader is created. It scans all of the active uniforms from the compiled shader and then builds an object containing their `WebGLUniformLocation` and a value cache. This saves redundant gl operations for both looking-up uniform locations and setting their values if they're already the currently set values by using the local cache instead. The `WebGLPipeline` classes offer a means to set uniform values on the shader (or shaders) belonging to the pipeline. Previously, calling a method such as `setFloat3` on a pipeline would pass that call over to `WebGLRenderer`. The renderer would first check to see if the pipeline program was current, and if not, make it so, before then looking up the uniform location and finally setting it. This is a lot of steps to take for pipelines that potentially need to change uniforms for every Game Object they render. Under the new methods, and using the new pre-cached uniform locations and values, these extra steps are skipped. The uniform value is set directly, no shader binding takes place and no location look-up happens. This dramatically reduces the number of WebGL ops being issued per frame. To clearly differentiate these pipeline methods, we have renamed them. The new method names are as follows: * `WebGLPipeline.set1f` will set a 1f uniform based on the given name. * `WebGLPipeline.set2f` will set a 2f uniform based on the given name. * `WebGLPipeline.set3f` will set a 3f uniform based on the given name. * `WebGLPipeline.set4f` will set a 4f uniform based on the given name. * `WebGLPipeline.set1fv` will set a 1fv uniform based on the given name. * `WebGLPipeline.set2fv` will set a 2fv uniform based on the given name. * `WebGLPipeline.set3fv` will set a 3fv uniform based on the given name. * `WebGLPipeline.set4fv` will set a 4fv uniform based on the given name. * `WebGLPipeline.set1iv` will set a 1iv uniform based on the given name. * `WebGLPipeline.set2iv` will set a 2iv uniform based on the given name. * `WebGLPipeline.set3iv` will set a 3iv uniform based on the given name. * `WebGLPipeline.set4iv` will set a 4iv uniform based on the given name. * `WebGLPipeline.set1i` will set a 1i uniform based on the given name. * `WebGLPipeline.set2i` will set a 2i uniform based on the given name. * `WebGLPipeline.set3i` will set a 3i uniform based on the given name. * `WebGLPipeline.set4i` will set a 4i uniform based on the given name. * `WebGLPipeline.setMatrix2fv` will set a matrix 2fv uniform based on the given name. * `WebGLPipeline.setMatrix3fv` will set a matrix 3fv uniform based on the given name. * `WebGLPipeline.setMatrix4fv` will set a matrix 4fv uniform based on the given name. If your code uses any of the old method names, please update them using the list below: * `WebGLPipeline.setFloat1` has been removed. Please use `set1f` instead. * `WebGLPipeline.setFloat2` has been removed. Please use `set2f` instead. * `WebGLPipeline.setFloat3` has been removed. Please use `set3f` instead. * `WebGLPipeline.setFloat4` has been removed. Please use `set4f` instead. * `WebGLPipeline.setFloat1v` has been removed. Please use `set1fv` instead. * `WebGLPipeline.setFloat2v` has been removed. Please use `set2fv` instead. * `WebGLPipeline.setFloat3v` has been removed. Please use `set3fv` instead. * `WebGLPipeline.setFloat4v` has been removed. Please use `set4fv` instead. * `WebGLPipeline.setInt1` has been removed. Please use `set1i` instead. * `WebGLPipeline.setInt2` has been removed. Please use `set2i` instead. * `WebGLPipeline.setInt3` has been removed. Please use `set3i` instead. * `WebGLPipeline.setInt4` has been removed. Please use `set4i` instead. * `WebGLPipeline.setMatrix1` has been removed. Please use `setMatrix2fv` instead. * `WebGLPipeline.setMatrix2` has been removed. Please use `setMatrix3fv` instead. * `WebGLPipeline.setMatrix3` has been removed. Please use `setMatrix4fv` instead. #### Game Object Pipeline Component Updates To support the new Post Pipelines in 3.50, the Pipeline Component which most Game Objects inherit has been updated. That means the following new properties and methods are available on all Game Objects that have this component, such as Sprite, Layer, Rope, etc. * `hasPostPipeline` is a new boolean property that indicates if the Game Object has one, or more post pipelines set. * `postPipelines` is a new property that contains an array of Post Pipelines owned by the Game Object. * `pipelineData` is a new object object to store pipeline specific data in. * The `setPipeline` method has been updated with 2 new parameters: `pipelineData` and `copyData`. These allow you to populate the pipeline data object during setting. * You can now pass a pipeline instance to the `setPipeline` method, as well as a string. * `setPostPipeline` is a new method that allows you to set one, or more, Post FX Pipelines on the Game Object. And optionally set the pipeline data with them. * `setPipelineData` is a new method that allows you to set a key/value pair into the pipeline data object in a chainable way. * `getPostPipeline` is a new method that will return a Post Pipeline instance from the Game Object based on the given string, function or instance. * The `resetPipeline` method has two new parameters `resetPostPipeline` and `resetData`, both false by default, that will reset the Post Pipelines and pipeline data accordingly. * `resetPostPipeline` is a new method that will specifically reset just the Post Pipelines, and optionally the pipeline data. * `removePostPipeline` is a new method that will destroy and remove the given Post Pipeline from the Game Object. #### Utility Pipeline The Utility Pipeline is a brand new default special-use WebGL Pipeline that is created by and belongs to the Pipeline Manager. It provides 4 shaders and handy associated methods: 1) Copy Shader. A fast texture to texture copy shader with optional brightness setting. 2) Additive Blend Mode Shader. Blends two textures using an additive blend mode. 3) Linear Blend Mode Shader. Blends two textures using a linear blend mode. 4) Color Matrix Copy Shader. Draws a texture to a target using a Color Matrix. You do not extend this pipeline, but instead get a reference to it from the Pipeline Manager via the `setUtility` method. You can also access its methods, such as `copyFrame`, directly from both the Pipeline Manager and from Post FX Pipelines, where its features are most useful. This pipeline provides methods for manipulating framebuffer backed textures, such as copying or blending one texture to another, copying a portion of a texture, additively blending two textures, flipping textures and more. All essential and common operations for post processing. The following properties and methods are available in the new `UtilityPipeline` class: * The `UtilityPipeline.colorMatrix` property is an instance of a ColorMatrix class, used by the draw shader. * The `UtilityPipeline.copyShader` property is a reference to the Copy Shader. * The `UtilityPipeline.addShader` property is a reference to the additive blend shader. * The `UtilityPipeline.linearShader` property is a reference to the linear blend shader. * The `UtilityPipeline.colorMatrixShader` property is a reference to the color matrix (draw) shader. * The `UtilityPipeline.fullFrame1` property is a full sized Render Target that can be used as a temporary buffer during post processing calls. * The `UtilityPipeline.fullFrame2` property is a full sized Render Target that can be used as a temporary buffer during post processing calls. * The `UtilityPipeline.halfFrame1` property is a half sized Render Target that can be used as a temporary buffer during post processing calls, where a small texture is required for more intensive operations. * The `UtilityPipeline.halfFrame2` property is a half sized Render Target that can be used as a temporary buffer during post processing calls, where a small texture is required for more intensive operations. * The `UtilityPipeline.copyFrame` method will copy a `source` Render Target to the `target` Render Target, optionally setting the brightness of the copy. * The `UtilityPipeline.blitFrame` method will copy a `source` Render Target to the `target` Render Target. Unlike `copyFrame` no resizing takes place and you can optionally set the brightness and erase mode of the copy. * The `UtilityPipeline.copyFrameRect` method binds the `source` Render Target and then copies a section of it to the `target` using `gl.copyTexSubImage2D` rather than a shader, making it much faster if you don't need blending or preserving alpha details. * The `UtilityPipeline.copyToGame` method pops the framebuffer from the renderers FBO stack and sets that as the active target, then draws the `source` Render Target to it. Use when you need to render the _final_ result to the game canvas. * The `UtilityPipeline.drawFrame` method will copy a `source` Render Target, optionally to a `target` Render Target, using the given ColorMatrix, allowing for full control over the luminance values used during the copy. * The `UtilityPipeline.blendFrames` method draws the `source1` and `source2` Render Targets to the `target` Render Target using a linear blend effect, which is controlled by the `strength` parameter. * The `UtilityPipeline.blendFramesAdditive` method draws the `source1` and `source2` Render Targets to the `target` Render Target using an additive blend effect, which is controlled by the `strength` parameter. * The `UtilityPipeline.clearFrame` method clears the given Render Target. * The `UtilityPipeline.setUVs` method allows you to set the UV values for the 6 vertices that make-up the quad belonging to the Utility Pipeline. * The `UtilityPipeline.setTargetUVs` method sets the vertex UV coordinates of the quad used by the shaders so that they correctly adjust the texture coordinates for a blit frame effect. * The `UtilityPipeline.flipX` method horizontally flips the UV coordinates of the quad used by the shaders. * The `UtilityPipeline.flipY` method vertically flips the UV coordinates of the quad used by the shaders. * The `UtilityPipeline.resetUVs` method resets the quad vertice UV values to their default settings. #### Light Pipeline Update 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 Game Objects now support rendering with normal maps. * Particle Emitter Game Object now supports rendering in Light2d. * The Text Game Object now supports render