Skip to content

Commit 6f3ec9f

Browse files
committed
All Game Objects now use GameObject.RENDER_MASK to compare against instead of a local property.
1 parent ebce634 commit 6f3ec9f

26 files changed

Lines changed: 131 additions & 79 deletions

v3/src/gameobjects/GameObject.js

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,93 @@
1+
/**
2+
* @author Richard Davey <rich@phaser.io>
3+
* @copyright 2017 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
17
var Class = require('../utils/Class');
28
var Components = require('./components');
39
var DataProxy = require('./components/DataProxy');
410

5-
/**
6-
* The base GameObject class that all Game Objects extend.
7-
*
8-
* @class GameObject
9-
*
10-
* @param {Scene} scene - The Scene to which this Game Object belongs.
11-
* @param {String} type - A textual representation of the Game Object.
12-
*/
1311
var GameObject = new Class({
1412

1513
initialize:
1614

15+
/**
16+
* The base class that all Game Objects extend.
17+
* You don't create GameObjects directly and they cannot be added to the display list.
18+
* Instead, use them as the base for your own custom classes.
19+
*
20+
* @class GameObject
21+
* @namespace Phaser.GameObjects
22+
* @constructor
23+
*
24+
* @param {Phaser.Scene} scene - The Scene to which this Game Object belongs.
25+
* @param {string} type - A textual representation of the type of Game Object, i.e. `sprite`.
26+
*/
1727
function GameObject (scene, type)
1828
{
1929
/**
2030
* The Scene to which this Game Object belongs.
31+
* Game Objects can only belong to one Scene.
2132
*
22-
* @property {Scene} scene
33+
* @property {Phaser.Scene} scene
2334
*/
2435
this.scene = scene;
2536

2637
/**
27-
* A textual representation of this Game Object.
38+
* A textual representation of this Game Object, i.e. `sprite`.
39+
* Used internally by Phaser but is available for your own custom classes to populate.
2840
*
29-
* @property {String} type
41+
* @property {string} type
3042
*/
3143
this.type = type;
3244

3345
/**
34-
* The name of this Game Object. Blank by default and not populated by Phaser. Left for developers use.
46+
* The name of this Game Object.
47+
* Empty by default and never populated by Phaser, this is left for developers to use.
3548
*
36-
* @property {String} [name='']
49+
* @property {string} [name='']
3750
*/
3851
this.name = '';
3952

4053
/**
41-
* The active state of this Game Object. A Game Object with an active state of `true` is processed by the UpdateList.
54+
* The active state of this Game Object.
55+
* A Game Object with an active state of `true` is processed by the Scenes UpdateList, if added to it.
4256
*
43-
* @property {Boolean} [active=true]
57+
* @property {boolean} [active=true]
4458
*/
4559
this.active = true;
4660

4761
/**
48-
* The Tab Index of this Game Object.
62+
* The Tab Index of the Game Object.
63+
* Reserved for future use by plugins and the Input Manager.
4964
*
50-
* @property {Integer} [tabIndex=-1]
65+
* @property {integer} [tabIndex=-1]
5166
*/
5267
this.tabIndex = -1;
5368

5469
/**
55-
* A proxy to the Data class. It allows you to store and query key/value paired information specific to this Game Object.
70+
* A proxy to the Data class.
71+
* It allows you to store, query and get key/value paired information specific to this Game Object.
5672
*
5773
* @property {DataProxy} data
5874
*/
5975
this.data = new DataProxy(scene, this);
6076

61-
/**
62-
* The bitmask that determines if the Game Object will render or not.
63-
* Structure: 0001 | 0010 | 0100 | 1000
64-
* The components: Visible, Alpha, Transform and Texture set bits in this mask respectively
65-
*
66-
* @property {Integer} [renderMask=15]
67-
* @private
68-
*/
69-
this.renderMask = 15;
70-
7177
/**
7278
* The flags that the renderMask uses to determine if the Game Object will render or not.
79+
* Structure: 0001 | 0010 | 0100 | 1000
80+
* The components Visible, Alpha, Transform and Texture set the bits in this mask respectively
7381
*
74-
* @property {Integer} [renderFlags=15]
82+
* @property {integer} [renderFlags=15]
7583
* @private
7684
*/
7785
this.renderFlags = 15;
7886

7987
/**
8088
* A bitmask that controls if this Game Object is drawn by a Camera or not.
8189
*
82-
* @property {Number} [cameraFilter=0]
90+
* @property {number} [cameraFilter=0]
8391
* @private
8492
*/
8593
this.cameraFilter = 0;
@@ -105,9 +113,9 @@ var GameObject = new Class({
105113
/**
106114
* Sets the `active` property of this Game Object and returns this Game Object for further chaining.
107115
*
108-
* @method GameObject#setActive
116+
* @method setActive
109117
*
110-
* @param {Boolean} value - True if this Game Object should be set as active, false if not.
118+
* @param {boolean} value - True if this Game Object should be set as active, false if not.
111119
* @return {GameObject} This GameObject.
112120
*/
113121
setActive: function (value)
@@ -120,9 +128,9 @@ var GameObject = new Class({
120128
/**
121129
* Sets the `name` property of this Game Object and returns this Game Object for further chaining.
122130
*
123-
* @method GameObject#setName
131+
* @method setName
124132
*
125-
* @param {String} value - The name to be given to this Game Object.
133+
* @param {string} value - The name to be given to this Game Object.
126134
* @return {GameObject} This GameObject.
127135
*/
128136
setName: function (value)
@@ -135,10 +143,10 @@ var GameObject = new Class({
135143
/**
136144
* Pass this Game Object to the Input Manager to enable it for Input.
137145
*
138-
* @method GameObject#setInteractive
146+
* @method setInteractive
139147
*
140-
* @param {[type]} [shape] - A geometric shape that defines the hit area for the Game Object. If not specified a Rectangle will be used.
141-
* @param {Function} [callback] - A callback to be invoked when the Game Object is interacted with.
148+
* @param {any} [shape] - A geometric shape that defines the hit area for the Game Object. If not specified a Rectangle will be used.
149+
* @param {function} [callback] - A callback to be invoked when the Game Object is interacted with.
142150
* @return {GameObject} This GameObject.
143151
*/
144152
setInteractive: function (shape, callback)
@@ -156,9 +164,9 @@ var GameObject = new Class({
156164
/**
157165
* Returns a JSON representation of the Game Object.
158166
*
159-
* @method GameObject#toJSON
167+
* @method toJSON
160168
*
161-
* @return {Object} A JSON representation of the Game Object.
169+
* @return {object} A JSON representation of the Game Object.
162170
*/
163171
toJSON: function ()
164172
{
@@ -168,13 +176,13 @@ var GameObject = new Class({
168176
/**
169177
* Compares the renderMask with the renderFlags to see if this Game Object will render or not.
170178
*
171-
* @method GameObject#willRender
179+
* @method willRender
172180
*
173-
* @return {Boolean} True if the Game Object should be rendered, otherwise false.
181+
* @return {boolean} True if the Game Object should be rendered, otherwise false.
174182
*/
175183
willRender: function ()
176184
{
177-
return (this.renderMask === this.renderFlags);
185+
return (GameObject.RENDER_MASK === this.renderFlags);
178186
},
179187

180188
/**
@@ -184,7 +192,7 @@ var GameObject = new Class({
184192
* you don't plan to use it again later. If you do wish to use it later then look at using
185193
* the Game Object Pool class instead.
186194
*
187-
* @method GameObject#destroy
195+
* @method destroy
188196
*/
189197
destroy: function ()
190198
{
@@ -208,4 +216,11 @@ var GameObject = new Class({
208216

209217
});
210218

219+
/**
220+
* The bitmask that `GameObject.renderFlags` is compared against to determine if the Game Object will render or not.
221+
*
222+
* @constant {integer} [RENDER_MASK=15]
223+
*/
224+
GameObject.RENDER_MASK = 15;
225+
211226
module.exports = GameObject;

v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextCanvasRenderer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
var GameObject = require('../../GameObject');
2+
13
var DynamicBitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage, camera)
24
{
35
var text = src.text;
46
var textLength = text.length;
57

6-
if (src.renderMask !== src.renderFlags || textLength === 0 || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
8+
if (GameObject.RENDER_MASK !== src.renderFlags || textLength === 0 || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
79
{
810
return;
911
}

v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextWebGLRenderer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var GameObject = require('../../GameObject');
12
var TransformMatrix = require('../../components/TransformMatrix');
23
var tempMatrix = new TransformMatrix();
34
var tempMatrixChar = new TransformMatrix();
@@ -7,7 +8,7 @@ var DynamicBitmapTextWebGLRenderer = function (renderer, gameObject, interpolati
78
var text = gameObject.text;
89
var textLength = text.length;
910

10-
if (this.renderMask !== this.renderFlags || textLength === 0 || (this.cameraFilter > 0 && (this.cameraFilter & camera._id)))
11+
if (GameObject.RENDER_MASK !== gameObject.renderFlags || textLength === 0 || (gameObject.cameraFilter > 0 && (gameObject.cameraFilter & camera._id)))
1112
{
1213
return;
1314
}

v3/src/gameobjects/bitmaptext/static/BitmapTextCanvasRenderer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
var GameObject = require('../../GameObject');
2+
13
var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage, camera)
24
{
35
var text = src.text;
46
var textLength = text.length;
57

6-
if (src.renderMask !== src.renderFlags || textLength === 0 || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
8+
if (GameObject.RENDER_MASK !== src.renderFlags || textLength === 0 || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
79
{
810
return;
911
}

v3/src/gameobjects/bitmaptext/static/BitmapTextWebGLRenderer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var GameObject = require('../../GameObject');
12
var TransformMatrix = require('../../components/TransformMatrix');
23
var tempMatrix = new TransformMatrix();
34

@@ -6,7 +7,7 @@ var BitmapTextWebGLRenderer = function (renderer, gameObject, interpolationPerce
67
var text = gameObject.text;
78
var textLength = text.length;
89

9-
if (this.renderMask !== this.renderFlags || textLength === 0 || (this.cameraFilter > 0 && (this.cameraFilter & camera._id)))
10+
if (GameObject.RENDER_MASK !== gameObject.renderFlags || textLength === 0 || (gameObject.cameraFilter > 0 && (gameObject.cameraFilter & camera._id)))
1011
{
1112
return;
1213
}

v3/src/gameobjects/blitter/BlitterCanvasRenderer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
var GameObject = require('../GameObject');
12

23
var BlitterCanvasRenderer = function (renderer, src, interpolationPercentage, camera)
34
{
4-
if (src.renderMask !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
5+
if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
56
{
67
return;
78
}

v3/src/gameobjects/blitter/BlitterWebGLRenderer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
var GameObject = require('../GameObject');
2+
13
var BlitterWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
24
{
3-
if (src.renderMask !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
5+
if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
46
{
57
return;
68
}

v3/src/gameobjects/effectlayer/EffectLayerWebGLRenderer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
var GameObject = require('../GameObject');
2+
13
var EffectLayerWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
24
{
3-
if (src.renderMask !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
5+
if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
46
{
57
return;
68
}

v3/src/gameobjects/graphics/GraphicsCanvasRenderer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
var Commands = require('./Commands');
22
var MATH_CONST = require('../../math/const');
3+
var GameObject = require('../GameObject');
34

45
var GraphicsCanvasRenderer = function (renderer, src, interpolationPercentage, camera, renderTargetCtx)
56
{
6-
if (src.renderMask !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
7+
if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
78
{
89
return;
910
}

v3/src/gameobjects/graphics/GraphicsWebGLRenderer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var GameObject = require('../GameObject');
12
var Commands = require('./Commands');
23
var TransformMatrix = require('../components/TransformMatrix');
34
var pathArray = [];
@@ -27,7 +28,7 @@ var Path = function (x, y, width, rgb, alpha)
2728

2829
var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercentage, camera, forceRenderTarget)
2930
{
30-
if (this.renderMask !== this.renderFlags || (this.cameraFilter > 0 && (this.cameraFilter & camera._id)))
31+
if (GameObject.RENDER_MASK !== gameObject.renderFlags || (gameObject.cameraFilter > 0 && (gameObject.cameraFilter & camera._id)))
3132
{
3233
return;
3334
}

0 commit comments

Comments
 (0)