@@ -172,124 +172,39 @@ TileBatch.prototype = {
172172 this . vertexBufferObject = null ;
173173 } ,
174174
175- addTileTexture : function ( gameObject , camera , texture , textureWidth , textureHeight )
176- {
177- var tempMatrix = this . tempMatrix ;
178- var alpha = 16777216 ;
179- var vertexDataBuffer = this . vertexDataBuffer ;
180- var vertexBufferObjectF32 = vertexDataBuffer . floatView ;
181- var vertexBufferObjectU32 = vertexDataBuffer . uintView ;
182- var vertexOffset = 0 ;
183- var width = textureWidth * ( gameObject . flipX ? - 1 : 1 ) ;
184- var height = textureHeight * ( gameObject . flipY ? - 1 : 1 ) ;
185- var translateX = gameObject . x - camera . scrollX ;
186- var translateY = gameObject . y - camera . scrollY ;
187- var scaleX = gameObject . scaleX ;
188- var scaleY = gameObject . scaleY ;
189- var rotation = - gameObject . rotation ;
190- var tempMatrixMatrix = tempMatrix . matrix ;
191- var x = - gameObject . displayOriginX + ( ( textureWidth ) * ( gameObject . flipX ? 1 : 0.0 ) ) ;
192- var y = - gameObject . displayOriginY + ( ( textureHeight ) * ( gameObject . flipY ? 1 : 0.0 ) ) ;
193- var xw = x + width ;
194- var yh = y + height ;
195- var cameraMatrix = camera . matrix . matrix ;
196- var mva , mvb , mvc , mvd , mve , mvf , tx0 , ty0 , tx1 , ty1 , tx2 , ty2 , tx3 , ty3 ;
197- var sra , srb , src , srd , sre , srf , cma , cmb , cmc , cmd , cme , cmf ;
198- var alpha = gameObject . alpha ;
199-
200- tempMatrix . applyITRS ( translateX , translateY , rotation , scaleX , scaleY ) ;
201-
202- sra = tempMatrixMatrix [ 0 ] ;
203- srb = tempMatrixMatrix [ 1 ] ;
204- src = tempMatrixMatrix [ 2 ] ;
205- srd = tempMatrixMatrix [ 3 ] ;
206- sre = tempMatrixMatrix [ 4 ] ;
207- srf = tempMatrixMatrix [ 5 ] ;
208-
209- cma = cameraMatrix [ 0 ] ;
210- cmb = cameraMatrix [ 1 ] ;
211- cmc = cameraMatrix [ 2 ] ;
212- cmd = cameraMatrix [ 3 ] ;
213- cme = cameraMatrix [ 4 ] ;
214- cmf = cameraMatrix [ 5 ] ;
215-
216- mva = sra * cma + srb * cmc ;
217- mvb = sra * cmb + srb * cmd ;
218- mvc = src * cma + srd * cmc ;
219- mvd = src * cmb + srd * cmd ;
220- mve = sre * cma + srf * cmc + cme ;
221- mvf = sre * cmb + srf * cmd + cmf ;
222-
223- tx0 = x * mva + y * mvc + mve ;
224- ty0 = x * mvb + y * mvd + mvf ;
225- tx1 = x * mva + yh * mvc + mve ;
226- ty1 = x * mvb + yh * mvd + mvf ;
227- tx2 = xw * mva + yh * mvc + mve ;
228- ty2 = xw * mvb + yh * mvd + mvf ;
229- tx3 = xw * mva + y * mvc + mve ;
230- ty3 = xw * mvb + y * mvd + mvf ;
231-
232- this . manager . setRenderer ( this , texture , gameObject . renderTarget ) ;
233- vertexOffset = vertexDataBuffer . allocate ( 24 ) ;
234- this . elementCount += 6 ;
235-
236- vertexBufferObjectF32 [ vertexOffset ++ ] = tx0 ;
237- vertexBufferObjectF32 [ vertexOffset ++ ] = ty0 ;
238- vertexBufferObjectF32 [ vertexOffset ++ ] = 0 ;
239- vertexBufferObjectF32 [ vertexOffset ++ ] = 0 ;
240- vertexBufferObjectU32 [ vertexOffset ++ ] = 0xFFFFFF ; //vertexColor.topLeft;
241- vertexBufferObjectF32 [ vertexOffset ++ ] = alpha ;
242-
243- vertexBufferObjectF32 [ vertexOffset ++ ] = tx1 ;
244- vertexBufferObjectF32 [ vertexOffset ++ ] = ty1 ;
245- vertexBufferObjectF32 [ vertexOffset ++ ] = 0 ;
246- vertexBufferObjectF32 [ vertexOffset ++ ] = 1 ;
247- vertexBufferObjectU32 [ vertexOffset ++ ] = 0xFFFFFF ; //vertexColor.bottomLeft;
248- vertexBufferObjectF32 [ vertexOffset ++ ] = alpha ;
249-
250- vertexBufferObjectF32 [ vertexOffset ++ ] = tx2 ;
251- vertexBufferObjectF32 [ vertexOffset ++ ] = ty2 ;
252- vertexBufferObjectF32 [ vertexOffset ++ ] = 1 ;
253- vertexBufferObjectF32 [ vertexOffset ++ ] = 1 ;
254- vertexBufferObjectU32 [ vertexOffset ++ ] = 0xFFFFFF ; //vertexColor.bottomRight;
255- vertexBufferObjectF32 [ vertexOffset ++ ] = alpha ;
256-
257- vertexBufferObjectF32 [ vertexOffset ++ ] = tx3 ;
258- vertexBufferObjectF32 [ vertexOffset ++ ] = ty3 ;
259- vertexBufferObjectF32 [ vertexOffset ++ ] = 1 ;
260- vertexBufferObjectF32 [ vertexOffset ++ ] = 0 ;
261- vertexBufferObjectU32 [ vertexOffset ++ ] = 0xFFFFFF ; //vertexColor.topRight;
262- vertexBufferObjectF32 [ vertexOffset ++ ] = alpha ;
263- } ,
264-
265175 addTileSprite : function ( gameObject , camera )
266176 {
267177 var tempMatrix = this . tempMatrix ;
268- var frame = gameObject . frame ;
269178 var alpha = 16777216 ;
270179 var vertexDataBuffer = this . vertexDataBuffer ;
271180 var vertexBufferObjectF32 = vertexDataBuffer . floatView ;
272181 var vertexBufferObjectU32 = vertexDataBuffer . uintView ;
273182 var vertexOffset = 0 ;
274- var uvs = frame . uvs ;
275- var width = frame . width * ( gameObject . flipX ? - 1 : 1 ) ;
276- var height = frame . height * ( gameObject . flipY ? - 1 : 1 ) ;
183+ var width = gameObject . width * ( gameObject . flipX ? - 1 : 1 ) ;
184+ var height = gameObject . height * ( gameObject . flipY ? - 1 : 1 ) ;
277185 var translateX = gameObject . x - camera . scrollX ;
278186 var translateY = gameObject . y - camera . scrollY ;
279187 var scaleX = gameObject . scaleX ;
280188 var scaleY = gameObject . scaleY ;
281189 var rotation = - gameObject . rotation ;
282190 var tempMatrixMatrix = tempMatrix . matrix ;
283- var x = - gameObject . displayOriginX + frame . x + ( ( frame . width ) * ( gameObject . flipX ? 1 : 0.0 ) ) ;
284- var y = - gameObject . displayOriginY + frame . y + ( ( frame . height ) * ( gameObject . flipY ? 1 : 0.0 ) ) ;
191+ var displayOriginX = gameObject . originX * gameObject . width ;
192+ var displayOriginY = gameObject . originY * gameObject . height ;
193+ var x = - displayOriginX + ( ( gameObject . width ) * ( gameObject . flipX ? 1 : 0.0 ) ) ;
194+ var y = - displayOriginY + ( ( gameObject . height ) * ( gameObject . flipY ? 1 : 0.0 ) ) ;
285195 var xw = x + width ;
286196 var yh = y + height ;
197+ var u0 = 0 ;
198+ var v0 = 0 ;
199+ var u1 = width / gameObject . frame . width ;
200+ var v1 = height / gameObject . frame . height ;
287201 var cameraMatrix = camera . matrix . matrix ;
288202 var mva , mvb , mvc , mvd , mve , mvf , tx0 , ty0 , tx1 , ty1 , tx2 , ty2 , tx3 , ty3 ;
289203 var sra , srb , src , srd , sre , srf , cma , cmb , cmc , cmd , cme , cmf ;
290204 var alpha = gameObject . alpha ;
291205 var tilePositionX = gameObject . tilePositionX / width ;
292206 var tilePositionY = gameObject . tilePositionY / height ;
207+ var texture = gameObject . tileTexture ;
293208
294209 tempMatrix . applyITRS ( translateX , translateY , rotation , scaleX , scaleY ) ;
295210
@@ -323,35 +238,35 @@ TileBatch.prototype = {
323238 tx3 = xw * mva + y * mvc + mve ;
324239 ty3 = xw * mvb + y * mvd + mvf ;
325240
326- this . manager . setRenderer ( this , frame . texture . source [ frame . sourceIndex ] . glTexture , gameObject . renderTarget ) ;
241+ this . manager . setRenderer ( this , texture , gameObject . renderTarget ) ;
327242 vertexOffset = vertexDataBuffer . allocate ( 24 ) ;
328243 this . elementCount += 6 ;
329244
330245 vertexBufferObjectF32 [ vertexOffset ++ ] = tx0 ;
331246 vertexBufferObjectF32 [ vertexOffset ++ ] = ty0 ;
332- vertexBufferObjectF32 [ vertexOffset ++ ] = uvs . x0 + tilePositionX ;
333- vertexBufferObjectF32 [ vertexOffset ++ ] = uvs . y0 + tilePositionY ;
247+ vertexBufferObjectF32 [ vertexOffset ++ ] = u0 + tilePositionX ;
248+ vertexBufferObjectF32 [ vertexOffset ++ ] = v0 + tilePositionY ;
334249 vertexBufferObjectU32 [ vertexOffset ++ ] = 0xFFFFFF ; //vertexColor.topLeft;
335250 vertexBufferObjectF32 [ vertexOffset ++ ] = alpha ;
336251
337252 vertexBufferObjectF32 [ vertexOffset ++ ] = tx1 ;
338253 vertexBufferObjectF32 [ vertexOffset ++ ] = ty1 ;
339- vertexBufferObjectF32 [ vertexOffset ++ ] = uvs . x1 + tilePositionX ;
340- vertexBufferObjectF32 [ vertexOffset ++ ] = uvs . y1 + tilePositionY ;
254+ vertexBufferObjectF32 [ vertexOffset ++ ] = u0 + tilePositionX ;
255+ vertexBufferObjectF32 [ vertexOffset ++ ] = v1 + tilePositionY ;
341256 vertexBufferObjectU32 [ vertexOffset ++ ] = 0xFFFFFF ; //vertexColor.bottomLeft;
342257 vertexBufferObjectF32 [ vertexOffset ++ ] = alpha ;
343258
344259 vertexBufferObjectF32 [ vertexOffset ++ ] = tx2 ;
345260 vertexBufferObjectF32 [ vertexOffset ++ ] = ty2 ;
346- vertexBufferObjectF32 [ vertexOffset ++ ] = uvs . x2 + tilePositionX ;
347- vertexBufferObjectF32 [ vertexOffset ++ ] = uvs . y2 + tilePositionY ;
261+ vertexBufferObjectF32 [ vertexOffset ++ ] = u1 + tilePositionX ;
262+ vertexBufferObjectF32 [ vertexOffset ++ ] = v1 + tilePositionY ;
348263 vertexBufferObjectU32 [ vertexOffset ++ ] = 0xFFFFFF ; //vertexColor.bottomRight;
349264 vertexBufferObjectF32 [ vertexOffset ++ ] = alpha ;
350265
351266 vertexBufferObjectF32 [ vertexOffset ++ ] = tx3 ;
352267 vertexBufferObjectF32 [ vertexOffset ++ ] = ty3 ;
353- vertexBufferObjectF32 [ vertexOffset ++ ] = uvs . x3 + tilePositionX ;
354- vertexBufferObjectF32 [ vertexOffset ++ ] = uvs . y3 + tilePositionY ;
268+ vertexBufferObjectF32 [ vertexOffset ++ ] = u1 + tilePositionX ;
269+ vertexBufferObjectF32 [ vertexOffset ++ ] = v0 + tilePositionY ;
355270 vertexBufferObjectU32 [ vertexOffset ++ ] = 0xFFFFFF ; //vertexColor.topRight;
356271 vertexBufferObjectF32 [ vertexOffset ++ ] = alpha ;
357272 }
0 commit comments