Added setState method.

This commit is contained in:
Richard Davey 2018-11-21 02:24:54 +00:00
parent 7c00bd4dc8
commit ab85d480a7
2 changed files with 27 additions and 2 deletions

View file

@ -33,6 +33,7 @@
* The WebGL Renderer has a new method `clearPipeline`, which will clear down the current pipeline and reset the blend mode, ready for the context to be passed to a 3rd party library.
* The WebGL Renderer has a new method `rebindPipeline`, which will rebind the given pipeline instance, reset the blank texture and reset the blend mode. Which is useful for recovering from 3rd party libs that have modified the gl context.
* Game Objects have a new property called `state`. Use this to track the state of a Game Object during its lifetime. For example, it could move from a state of 'moving', to 'attacking', to 'dead'. Phaser itself will never set this property, although plugins are allowed to.
* Game Objects have a new method called `setState` which will set the state property in a chainable call.
* `BlendModes.ERASE` is a new blend mode that will erase the object being drawn. When used in conjunction with a Render Texture it allows for effects that let you erase parts of the texture, in either Canvas or WebGL. When used with a transparent game canvas, it allows you to erase parts of the canvas, showing the web page background through.
* `BlendModes.SOURCE_IN` is a new Canvas-only blend mode, that allows you to use the `source-in` composite operation when rendering Game Objects.
* `BlendModes.SOURCE_OUT` is a new Canvas-only blend mode, that allows you to use the `source-out` composite operation when rendering Game Objects.

View file

@ -61,8 +61,8 @@ var GameObject = new Class({
* Phaser itself will never modify this value, although plugins may do so.
*
* Use this property to track the state of a Game Object during its lifetime. For example, it could move from
* a state of 'moving', to 'attacking', to 'dead'. The state value should typically be an integer (ideally mapped to a constant
* in your game code), but could also be a string, or any other data-type. It is recommended to keep it light and simple.
* a state of 'moving', to 'attacking', to 'dead'. The state value should be an integer (ideally mapped to a constant
* in your game code), or a string. These are recommended to keep it light and simple, with fast comparisons.
* If you need to store complex data about your Game Object, look at using the Data Component instead.
*
* @name Phaser.GameObjects.GameObject#state
@ -227,6 +227,30 @@ var GameObject = new Class({
return this;
},
/**
* Sets the current state of this Game Object.
*
* Phaser itself will never modify the State of a Game Object, although plugins may do so.
*
* For example, a Game Object could change from a state of 'moving', to 'attacking', to 'dead'.
* The state value should typically be an integer (ideally mapped to a constant
* in your game code), but could also be a string. It is recommended to keep it light and simple.
* If you need to store complex data about your Game Object, look at using the Data Component instead.
*
* @method Phaser.GameObjects.GameObject#setState
* @since 3.16.0
*
* @param {(integer|string)} value - The state of the Game Object.
*
* @return {this} This GameObject.
*/
setState: function (value)
{
this.state = value;
return this;
},
/**
* Adds a Data Manager component to this Game Object.
*