@@ -439,6 +439,112 @@ var SpriteBatch = new Class({
439439 vertexBufferObjectF32 [ vertexOffset ++ ] = alpha ;
440440 } ,
441441
442+ addSpriteTextureRect : function ( gameObject , camera , texture , rectX , rectY , rectWidth , rectHeight , textureWidth , textureHeight )
443+ {
444+ var tempMatrix = this . tempMatrix ;
445+ var vertexDataBuffer = this . vertexDataBuffer ;
446+ var vertexBufferObjectF32 = vertexDataBuffer . floatView ;
447+ var vertexBufferObjectU32 = vertexDataBuffer . uintView ;
448+ var vertexOffset = 0 ;
449+ var width = rectWidth * ( gameObject . flipX ? - 1 : 1 ) ;
450+ var height = rectHeight * ( gameObject . flipY ? - 1 : 1 ) ;
451+ var translateX = gameObject . x - camera . scrollX * gameObject . scrollFactorX ;
452+ var translateY = gameObject . y - camera . scrollY * gameObject . scrollFactorY ;
453+ var scaleX = gameObject . scaleX ;
454+ var scaleY = gameObject . scaleY ;
455+ var rotation = - gameObject . rotation ;
456+ var tempMatrixMatrix = tempMatrix . matrix ;
457+ var x = - gameObject . displayOriginX + ( ( rectWidth ) * ( gameObject . flipX ? 1 : 0.0 ) ) ;
458+ var y = - gameObject . displayOriginY + ( ( rectHeight ) * ( gameObject . flipY ? 1 : 0.0 ) ) ;
459+ var xw = x + rectWidth ;
460+ var yh = y + rectHeight ;
461+ var cameraMatrix = camera . matrix . matrix ;
462+ var mva , mvb , mvc , mvd , mve , mvf , tx0 , ty0 , tx1 , ty1 , tx2 , ty2 , tx3 , ty3 ;
463+ var sra , srb , src , srd , sre , srf , cma , cmb , cmc , cmd , cme , cmf ;
464+ var alphaTL = gameObject . _alphaTL ;
465+ var alphaTR = gameObject . _alphaTR ;
466+ var alphaBL = gameObject . _alphaBL ;
467+ var alphaBR = gameObject . _alphaBR ;
468+ var tintTL = gameObject . _tintTL ;
469+ var tintTR = gameObject . _tintTR ;
470+ var tintBL = gameObject . _tintBL ;
471+ var tintBR = gameObject . _tintBR ;
472+ var u0 = 0 ; // rectX / textureWidth;
473+ var v0 = 0 ; // rectY / textureHeight;
474+ var u1 = 1 ; // u0 + (rectWidth / textureWidth);
475+ var v1 = 1 ; // v0 + (rectHeight / textureHeight);
476+
477+ tempMatrix . applyITRS ( translateX , translateY , rotation , scaleX , scaleY ) ;
478+
479+ sra = tempMatrixMatrix [ 0 ] ;
480+ srb = tempMatrixMatrix [ 1 ] ;
481+ src = tempMatrixMatrix [ 2 ] ;
482+ srd = tempMatrixMatrix [ 3 ] ;
483+ sre = tempMatrixMatrix [ 4 ] ;
484+ srf = tempMatrixMatrix [ 5 ] ;
485+
486+ cma = cameraMatrix [ 0 ] ;
487+ cmb = cameraMatrix [ 1 ] ;
488+ cmc = cameraMatrix [ 2 ] ;
489+ cmd = cameraMatrix [ 3 ] ;
490+ cme = cameraMatrix [ 4 ] ;
491+ cmf = cameraMatrix [ 5 ] ;
492+
493+ mva = sra * cma + srb * cmc ;
494+ mvb = sra * cmb + srb * cmd ;
495+ mvc = src * cma + srd * cmc ;
496+ mvd = src * cmb + srd * cmd ;
497+ mve = sre * cma + srf * cmc + cme ;
498+ mvf = sre * cmb + srf * cmd + cmf ;
499+
500+ tx0 = x * mva + y * mvc + mve ;
501+ ty0 = x * mvb + y * mvd + mvf ;
502+ tx1 = x * mva + yh * mvc + mve ;
503+ ty1 = x * mvb + yh * mvd + mvf ;
504+ tx2 = xw * mva + yh * mvc + mve ;
505+ ty2 = xw * mvb + yh * mvd + mvf ;
506+ tx3 = xw * mva + y * mvc + mve ;
507+ ty3 = xw * mvb + y * mvd + mvf ;
508+
509+ this . manager . setRenderer ( this , texture , gameObject . renderTarget ) ;
510+ this . drawIndexed = true ;
511+ this . drawingMesh = false ;
512+ vertexOffset = vertexDataBuffer . allocate ( 24 ) ;
513+ this . elementCount += 6 ;
514+
515+ // Top Left
516+ vertexBufferObjectF32 [ vertexOffset ++ ] = tx0 ;
517+ vertexBufferObjectF32 [ vertexOffset ++ ] = ty0 ;
518+ vertexBufferObjectF32 [ vertexOffset ++ ] = u0 ;
519+ vertexBufferObjectF32 [ vertexOffset ++ ] = v0 ;
520+ vertexBufferObjectU32 [ vertexOffset ++ ] = tintTL ;
521+ vertexBufferObjectF32 [ vertexOffset ++ ] = alphaTL ;
522+
523+ // Bottom Left
524+ vertexBufferObjectF32 [ vertexOffset ++ ] = tx1 ;
525+ vertexBufferObjectF32 [ vertexOffset ++ ] = ty1 ;
526+ vertexBufferObjectF32 [ vertexOffset ++ ] = u0 ;
527+ vertexBufferObjectF32 [ vertexOffset ++ ] = v1 ;
528+ vertexBufferObjectU32 [ vertexOffset ++ ] = tintBL ;
529+ vertexBufferObjectF32 [ vertexOffset ++ ] = alphaBL ;
530+
531+ // Bottom Right
532+ vertexBufferObjectF32 [ vertexOffset ++ ] = tx2 ;
533+ vertexBufferObjectF32 [ vertexOffset ++ ] = ty2 ;
534+ vertexBufferObjectF32 [ vertexOffset ++ ] = u1 ;
535+ vertexBufferObjectF32 [ vertexOffset ++ ] = v1 ;
536+ vertexBufferObjectU32 [ vertexOffset ++ ] = tintBR ;
537+ vertexBufferObjectF32 [ vertexOffset ++ ] = alphaBR ;
538+
539+ // Top Right
540+ vertexBufferObjectF32 [ vertexOffset ++ ] = tx3 ;
541+ vertexBufferObjectF32 [ vertexOffset ++ ] = ty3 ;
542+ vertexBufferObjectF32 [ vertexOffset ++ ] = u1 ;
543+ vertexBufferObjectF32 [ vertexOffset ++ ] = v0 ;
544+ vertexBufferObjectU32 [ vertexOffset ++ ] = tintTR ;
545+ vertexBufferObjectF32 [ vertexOffset ++ ] = alphaTR ;
546+ } ,
547+
442548 addSpriteTexture : function ( gameObject , camera , texture , textureWidth , textureHeight )
443549 {
444550 var tempMatrix = this . tempMatrix ;
0 commit comments