@@ -449,39 +449,67 @@ Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', {
449449 */
450450PIXI . DisplayObject . prototype . updateTransform = function ( )
451451{
452- // TODO OPTIMIZE THIS!! with dirty
453- if ( this . rotation !== this . rotationCache )
454- {
455-
456- this . rotationCache = this . rotation ;
457- this . _sr = Math . sin ( this . rotation ) ;
458- this . _cr = Math . cos ( this . rotation ) ;
459- }
452+ // create some matrix refs for easy access
453+ var pt = this . parent . worldTransform ;
454+ var wt = this . worldTransform ;
460455
461- // var localTransform = this.localTransform//.toArray();
462- var parentTransform = this . parent . worldTransform ; //.toArray();
463- var worldTransform = this . worldTransform ; //.toArray();
456+ // temporary matrix variables
457+ var a , b , c , d , tx , ty ;
464458
465- var px = this . pivot . x ;
466- var py = this . pivot . y ;
459+ // TODO create a const for 2_PI
460+ // so if rotation is between 0 then we can simplify the multiplication process..
461+ if ( this . rotation % PIXI . PI_2 )
462+ {
463+ // check to see if the rotation is the same as the previous render. This means we only need to use sin and cos when rotation actually changes
464+ if ( this . rotation !== this . rotationCache )
465+ {
466+ this . rotationCache = this . rotation ;
467+ this . _sr = Math . sin ( this . rotation ) ;
468+ this . _cr = Math . cos ( this . rotation ) ;
469+ }
467470
468- var a00 = this . _cr * this . scale . x ,
469- a01 = - this . _sr * this . scale . y ,
470- a10 = this . _sr * this . scale . x ,
471- a11 = this . _cr * this . scale . y ,
472- a02 = this . position . x - a00 * px - py * a01 ,
473- a12 = this . position . y - a11 * py - px * a10 ,
474- b00 = parentTransform . a , b01 = parentTransform . b ,
475- b10 = parentTransform . c , b11 = parentTransform . d ;
471+ // get the matrix values of the displayobject based on its transform properties..
472+ a = this . _cr * this . scale . x ;
473+ b = this . _sr * this . scale . x ;
474+ c = - this . _sr * this . scale . y ;
475+ d = this . _cr * this . scale . y ;
476+ tx = this . position . x ;
477+ ty = this . position . y ;
478+
479+ // check for pivot.. not often used so geared towards that fact!
480+ if ( this . pivot . x || this . pivot . y )
481+ {
482+ tx -= this . pivot . x * a + this . pivot . y * c ;
483+ ty -= this . pivot . x * b + this . pivot . y * d ;
484+ }
476485
477- worldTransform . a = b00 * a00 + b01 * a10 ;
478- worldTransform . b = b00 * a01 + b01 * a11 ;
479- worldTransform . tx = b00 * a02 + b01 * a12 + parentTransform . tx ;
486+ // concat the parent matrix with the objects transform.
487+ wt . a = a * pt . a + b * pt . c ;
488+ wt . b = a * pt . b + b * pt . d ;
489+ wt . c = c * pt . a + d * pt . c ;
490+ wt . d = c * pt . b + d * pt . d ;
491+ wt . tx = tx * pt . a + ty * pt . c + pt . tx ;
492+ wt . ty = tx * pt . b + ty * pt . d + pt . ty ;
480493
481- worldTransform . c = b10 * a00 + b11 * a10 ;
482- worldTransform . d = b10 * a01 + b11 * a11 ;
483- worldTransform . ty = b10 * a02 + b11 * a12 + parentTransform . ty ;
494+
495+ }
496+ else
497+ {
498+ // lets do the fast version as we know there is no rotation..
499+ a = this . scale . x ;
500+ d = this . scale . y ;
501+ tx = this . position . x - this . pivot . x * a ;
502+ ty = this . position . y - this . pivot . y * d ;
503+
504+ wt . a = pt . a * a ;
505+ wt . b = pt . b * d ;
506+ wt . c = pt . c * a ;
507+ wt . d = pt . d * d ;
508+ wt . tx = tx * pt . a + ty * pt . c + pt . tx ;
509+ wt . ty = tx * pt . b + ty * pt . d + pt . ty ;
510+ }
484511
512+ // multiply the alphas..
485513 this . worldAlpha = this . alpha * this . parent . worldAlpha ;
486514} ;
487515
@@ -520,11 +548,20 @@ PIXI.DisplayObject.prototype.setStageReference = function(stage)
520548 if ( this . _interactive ) this . stage . dirty = true ;
521549} ;
522550
523- PIXI . DisplayObject . prototype . generateTexture = function ( renderer )
551+ /**
552+ * Useful function that returns a texture of the displayObject object that can then be used to create sprites
553+ * This can be quite useful if your displayObject is static / complicated and needs to be reused multiple times.
554+ *
555+ * @method generateTexture
556+ * @param resolution {Number} The resolution of the texture being generated
557+ * @param scaleMode {Number} Should be one of the PIXI.scaleMode consts
558+ * @return {Texture } a texture of the graphics object
559+ */
560+ PIXI . DisplayObject . prototype . generateTexture = function ( resolution , scaleMode , renderer )
524561{
525562 var bounds = this . getLocalBounds ( ) ;
526563
527- var renderTexture = new PIXI . RenderTexture ( bounds . width | 0 , bounds . height | 0 , renderer ) ;
564+ var renderTexture = new PIXI . RenderTexture ( bounds . width | 0 , bounds . height | 0 , renderer , scaleMode , resolution ) ;
528565 renderTexture . render ( this , new PIXI . Point ( - bounds . x , - bounds . y ) ) ;
529566
530567 return renderTexture ;
@@ -602,7 +639,11 @@ PIXI.DisplayObject.prototype._generateCachedSprite = function()//renderSession)
602639 this . _filters = null ;
603640
604641 this . _cachedSprite . filters = tempFilters ;
605- this . _cachedSprite . texture . render ( this , new PIXI . Point ( - bounds . x , - bounds . y ) ) ;
642+
643+ PIXI . DisplayObject . _tempMatrix . tx = - bounds . x ;
644+ PIXI . DisplayObject . _tempMatrix . ty = - bounds . y ;
645+
646+ this . _cachedSprite . texture . render ( this , PIXI . DisplayObject . _tempMatrix ) ;
606647
607648 this . _cachedSprite . anchor . x = - ( bounds . x / bounds . width ) ;
608649 this . _cachedSprite . anchor . y = - ( bounds . y / bounds . height ) ;
@@ -652,6 +693,9 @@ PIXI.DisplayObject.prototype._renderCanvas = function(renderSession)
652693 renderSession = renderSession ;
653694} ;
654695
696+
697+ PIXI . DisplayObject . _tempMatrix = new PIXI . Matrix ( ) ;
698+
655699/**
656700 * The position of the displayObject on the x axis relative to the local coordinates of the parent.
657701 *
@@ -681,3 +725,5 @@ Object.defineProperty(PIXI.DisplayObject.prototype, 'y', {
681725 this . position . y = value ;
682726 }
683727} ) ;
728+
729+
0 commit comments