@@ -69,6 +69,8 @@ var DOMElement = new Class({
6969 this . rotate3d = new Vector4 ( ) ;
7070 this . rotate3dAngle = 'deg' ;
7171
72+ this . handler = this . dispatchNativeEvent . bind ( this ) ;
73+
7274 this . setPosition ( x , y ) ;
7375
7476 if ( element )
@@ -88,6 +90,20 @@ var DOMElement = new Class({
8890 return this ;
8991 } ,
9092
93+ perspective : {
94+
95+ get : function ( )
96+ {
97+ return parseFloat ( this . parent . style . perspective ) ;
98+ } ,
99+
100+ set : function ( value )
101+ {
102+ this . parent . style . perspective = value + 'px' ;
103+ }
104+
105+ } ,
106+
91107 setPerspective : function ( value )
92108 {
93109 // Sets it on the DOM Container!
@@ -96,31 +112,31 @@ var DOMElement = new Class({
96112 return this ;
97113 } ,
98114
99- /**
100- * Compares the renderMask with the renderFlags to see if this Game Object will render or not.
101- *
102- * @method Phaser.GameObjects.GameObject#willRender
103- * @since 3.0.0
104- *
105- * @return {boolean } True if the Game Object should be rendered, otherwise false.
106- */
107- willRender : function ( )
115+ addListener : function ( events )
108116 {
109- return true ;
110- } ,
111-
112- listen : function ( events )
113- {
114- if ( ! this . node )
117+ if ( this . node )
115118 {
116- return ;
119+ events = events . split ( ' ' ) ;
120+
121+ for ( var i = 0 ; i < events . length ; i ++ )
122+ {
123+ this . node . addEventListener ( events [ i ] , this . handler , false ) ;
124+ }
117125 }
118126
119- events = events . split ( ' ' ) ;
127+ return this ;
128+ } ,
120129
121- for ( var i = 0 ; i < events . length ; i ++ )
130+ removeListener : function ( events )
131+ {
132+ if ( this . node )
122133 {
123- this . node . addEventListener ( events [ i ] , this . dispatchNativeEvent . bind ( this ) , false ) ;
134+ events = events . split ( ' ' ) ;
135+
136+ for ( var i = 0 ; i < events . length ; i ++ )
137+ {
138+ this . node . removeEventListener ( events [ i ] , this . handler ) ;
139+ }
124140 }
125141
126142 return this ;
@@ -157,7 +173,7 @@ var DOMElement = new Class({
157173
158174 // Node handler
159175
160- target . phaserElement = this ;
176+ target . phaser = this ;
161177
162178 if ( this . parent )
163179 {
@@ -180,13 +196,58 @@ var DOMElement = new Class({
180196 {
181197 if ( elementType === undefined ) { elementType = 'div' ; }
182198
183- console . log ( html ) ;
184-
185199 var element = document . createElement ( elementType ) ;
186200
201+ this . node = element ;
202+
203+ element . style . zIndex = '0' ;
204+ element . style . display = 'inline' ;
205+ element . style . position = 'absolute' ;
206+
207+ // Node handler
208+
209+ element . phaser = this ;
210+
211+ if ( this . parent )
212+ {
213+ this . parent . appendChild ( element ) ;
214+ }
215+
187216 element . innerHTML = html ;
188217
189- return this . setElement ( element ) ;
218+ var nodeBounds = element . getBoundingClientRect ( ) ;
219+
220+ this . setSize ( nodeBounds . width || 0 , nodeBounds . height || 0 ) ;
221+
222+ return this ;
223+ } ,
224+
225+ getChildByProperty : function ( property , value )
226+ {
227+ if ( this . node )
228+ {
229+ var children = this . node . querySelectorAll ( '*' ) ;
230+
231+ for ( var i = 0 ; i < children . length ; i ++ )
232+ {
233+ if ( children [ i ] [ property ] === value )
234+ {
235+ return children [ i ] ;
236+ }
237+ }
238+ }
239+
240+ return null ;
241+ } ,
242+
243+ getChildByID : function ( id )
244+ {
245+ return this . getChildByProperty ( 'id' , id ) ;
246+ } ,
247+
248+ getChildByName : function ( name )
249+ {
250+ return this . getChildByProperty ( 'name' , name ) ;
190251 } ,
191252
192253 setText : function ( text )
@@ -209,6 +270,21 @@ var DOMElement = new Class({
209270 return this ;
210271 } ,
211272
273+ /**
274+ * Compares the renderMask with the renderFlags to see if this Game Object will render or not.
275+ *
276+ * DOMElements always return `true` as they need to still set values during the render pass, even if not visible.
277+ *
278+ * @method Phaser.GameObjects.DOMElement#willRender
279+ * @since 3.12.0
280+ *
281+ * @return {boolean } True if the Game Object should be rendered, otherwise false.
282+ */
283+ willRender : function ( )
284+ {
285+ return true ;
286+ } ,
287+
212288 destroy : function ( )
213289 {
214290
0 commit comments