@@ -2,55 +2,165 @@ var Class = require('../utils/Class');
22var Components = require ( './components' ) ;
33var DataProxy = require ( './components/DataProxy' ) ;
44
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+ */
513var GameObject = new Class ( {
614
715 initialize :
816
917 function GameObject ( scene , type )
1018 {
19+ /**
20+ * The Scene to which this Game Object belongs.
21+ *
22+ * @property
23+ * @type {Scene }
24+ */
1125 this . scene = scene ;
1226
27+ /**
28+ * A textual representation of this Game Object.
29+ *
30+ * @property
31+ * @type {string }
32+ */
1333 this . type = type ;
1434
35+ /**
36+ * The name of this Game Object. Blank by default and not populated by Phaser. Left for developers use.
37+ *
38+ * @property
39+ * @type {String }
40+ */
1541 this . name = '' ;
1642
43+ /**
44+ * The active state of this Game Object. A Game Object with an active state of `true` is processed by the UpdateList.
45+ *
46+ * @property
47+ * @type {Boolean }
48+ */
1749 this . active = true ;
1850
51+ /**
52+ * The Tab Index of this Game Object.
53+ *
54+ * @property
55+ * @type {Number }
56+ */
1957 this . tabIndex = - 1 ;
2058
59+ /**
60+ * A proxy to the Data class. It allows you to store and query key/value paired information specific to this Game Object.
61+ *
62+ * @property
63+ * @type {DataProxy }
64+ */
2165 this . data = new DataProxy ( scene , this ) ;
2266
23- // 0001 | 0010 | 0100 | 1000
24- // Will Render bitmask flags for the components Visible, Alpha, Transform and Texture respectively
67+ /**
68+ * The bitmask that determines if the Game Object will render or not.
69+ * Structure: 0001 | 0010 | 0100 | 1000
70+ * The components: Visible, Alpha, Transform and Texture set bits in this mask respectively
71+ *
72+ * @property
73+ * @type {Number }
74+ * @private
75+ */
2576 this . renderMask = 15 ;
77+
78+ /**
79+ * The flags that the renderMask uses to determine if the Game Object will render or not.
80+ *
81+ * @property
82+ * @type {Number }
83+ * @private
84+ */
2685 this . renderFlags = 15 ;
86+
87+ /**
88+ * A bitmask that controls if this Game Object is drawn by a Camera or not.
89+ *
90+ * @property
91+ * @type {Number }
92+ * @private
93+ */
2794 this . cameraFilter = 0 ;
2895
29- // instance of Phaser.Input.InteractiveObject if input enabled
96+ /**
97+ * If this Game Object is enabled for input then this property will contain a Phaser.Input.InteractiveObject reference.
98+ *
99+ * @property
100+ * @type {Phaser.Input.InteractiveObject|null }
101+ */
30102 this . input = null ;
31103
32- // instance of Phaser.Physics.X.Body if physics enabled (X = the physics system being used by the Scene)
104+ /**
105+ * If this Game Object is enabled for physics then this property will contain a reference to a Physics Body.
106+ *
107+ * @property
108+ * @type {Phaser.Physics.Body|null }
109+ */
33110 this . body = null ;
34111
35- // Trigger a scene z-depth sort
112+ /**
113+ * Should this Game Object trigger a Scene level z-depth sort?
114+ * Automatically set by various components but can also be set manually as required.
115+ *
116+ * @property
117+ * @type {Boolean }
118+ */
36119 this . scene . sys . sortChildrenFlag = true ;
37120 } ,
38121
39- // For GameObject Pooling and item selection
122+ /**
123+ * Sets the `active` property of this Game Object and returns this Game Object for further chaining.
124+ *
125+ * @method setActive
126+ * @memberof GameObject#
127+ *
128+ * @param {Boolean } value - True if this Game Object should be set as active, false if not.
129+ * @returns {this }
130+ */
40131 setActive : function ( value )
41132 {
42133 this . active = value ;
43134
44135 return this ;
45136 } ,
46137
138+ /**
139+ * Sets the `name` property of this Game Object and returns this Game Object for further chaining.
140+ *
141+ * @method setName
142+ * @memberof GameObject#
143+ *
144+ * @param {String } value - The name to be given to this Game Object.
145+ * @returns {this }
146+ */
47147 setName : function ( value )
48148 {
49149 this . name = value ;
50150
51151 return this ;
52152 } ,
53153
154+ /**
155+ * Pass this Game Object to the Input Manager to enable it for Input.
156+ *
157+ * @method setInteractive
158+ * @memberof GameObject#
159+ *
160+ * @param {[type] } [shape] - A geometric shape that defines the hit area for the Game Object. If not specified a Rectangle will be used.
161+ * @param {Function } [callback] - A callback to be invoked when the Game Object is interacted with.
162+ * @returns {this }
163+ */
54164 setInteractive : function ( shape , callback )
55165 {
56166 this . scene . sys . inputManager . enable ( this , shape , callback ) ;
@@ -63,17 +173,42 @@ var GameObject = new Class({
63173 {
64174 } ,
65175
66- // Can be overridden by custom Game Objects, but provides default export functionality
176+ /**
177+ * Returns a JSON representation of the Game Object.
178+ *
179+ * @method toJSON
180+ * @memberof GameObject#
181+ *
182+ * @return {Object } A JSON representation of the Game Object.
183+ */
67184 toJSON : function ( )
68185 {
69186 return Components . ToJSON ( this ) ;
70187 } ,
71188
189+ /**
190+ * Compares the renderMask with the renderFlags to see if this Game Object will render or not.
191+ *
192+ * @method willRender
193+ * @memberof GameObject#
194+ *
195+ * @return {Boolean } True if the Game Object should be rendered, otherwise false.
196+ */
72197 willRender : function ( )
73198 {
74199 return ( this . renderMask === this . renderFlags ) ;
75200 } ,
76201
202+ /**
203+ * Destroys this Game Object, removing it from the Display List and Update List.
204+ * Also removes it from the Input and Physics Managers if enabled.
205+ * Sets the active state to `false`. Use this to remove a Game Object from your game if
206+ * you don't plan to use it again later. If you do wish to use it later then look at using
207+ * the Game Object Pool class instead.
208+ *
209+ * @method destroy
210+ * @memberof GameObject#
211+ */
77212 destroy : function ( )
78213 {
79214 this . scene . sys . displayList . remove ( this ) ;
0 commit comments