@@ -172,7 +172,6 @@ PIXI.Sprite.prototype.onTextureUpdate = function()
172172*/
173173PIXI . Sprite . prototype . getBounds = function ( matrix )
174174{
175-
176175 var width = this . texture . frame . width ;
177176 var height = this . texture . frame . height ;
178177
@@ -320,31 +319,30 @@ PIXI.Sprite.prototype._renderCanvas = function(renderSession)
320319 // if the sprite is not visible or the alpha is 0 then no need to render this element
321320 if ( this . visible === false || this . alpha === 0 ) return ;
322321
323- var frame = this . texture . frame ;
324322 var context = renderSession . context ;
325323 var texture = this . texture ;
324+ var frame = texture . frame ;
325+ var crop = texture . crop ;
326326
327- if ( this . blendMode !== renderSession . currentBlendMode )
327+ if ( this . blendMode !== renderSession . currentBlendMode )
328328 {
329329 renderSession . currentBlendMode = this . blendMode ;
330330 context . globalCompositeOperation = PIXI . blendModesCanvas [ renderSession . currentBlendMode ] ;
331331 }
332332
333- if ( this . _mask )
333+ if ( this . _mask )
334334 {
335335 renderSession . maskManager . pushMask ( this . _mask , renderSession . context ) ;
336336 }
337337
338-
339-
340- //ignore null sources
341- if ( texture . valid )
338+ // Ignore null sources
339+ if ( texture . valid )
342340 {
343341 context . globalAlpha = this . worldAlpha ;
344342
345343 var transform = this . worldTransform ;
346344
347- // allow for trimming
345+ // Allow for trimming
348346 if ( renderSession . roundPixels )
349347 {
350348 context . setTransform ( transform . a , transform . c , transform . b , transform . d , transform . tx | 0 , transform . ty | 0 ) ;
@@ -354,28 +352,41 @@ PIXI.Sprite.prototype._renderCanvas = function(renderSession)
354352 context . setTransform ( transform . a , transform . c , transform . b , transform . d , transform . tx , transform . ty ) ;
355353 }
356354
357- //if smoothingEnabled is supported and we need to change the smoothing property for this texture
358- if ( renderSession . smoothProperty && renderSession . scaleMode !== this . texture . baseTexture . scaleMode ) {
355+ // If smoothingEnabled is supported and we need to change the smoothing property for this texture
356+ if ( renderSession . smoothProperty && renderSession . scaleMode !== this . texture . baseTexture . scaleMode )
357+ {
359358 renderSession . scaleMode = this . texture . baseTexture . scaleMode ;
360359 context [ renderSession . smoothProperty ] = ( renderSession . scaleMode === PIXI . scaleModes . LINEAR ) ;
361360 }
362361
363- if ( this . tint !== 0xFFFFFF )
362+ if ( this . tint !== 0xFFFFFF )
364363 {
365-
366- if ( this . cachedTint !== this . tint )
364+ if ( this . cachedTint !== this . tint )
367365 {
368366 // no point tinting an image that has not loaded yet!
369- if ( ! texture . baseTexture . hasLoaded ) return ;
367+ if ( ! texture . baseTexture . hasLoaded ) return ;
370368
371369 this . cachedTint = this . tint ;
372370
373371 //TODO clean up caching - how to clean up the caches?
374372 this . tintedTexture = PIXI . CanvasTinter . getTintedTexture ( this , this . tint ) ;
375-
376373 }
377374
378- context . drawImage ( this . tintedTexture ,
375+ if ( texture . trim )
376+ {
377+ context . drawImage ( this . tintedTexture ,
378+ 0 ,
379+ 0 ,
380+ crop . width ,
381+ crop . height ,
382+ texture . trim . x - this . anchor . x * texture . trim . width ,
383+ texture . trim . y - this . anchor . y * texture . trim . height ,
384+ crop . width ,
385+ crop . height ) ;
386+ }
387+ else
388+ {
389+ context . drawImage ( this . tintedTexture ,
379390 0 ,
380391 0 ,
381392 frame . width ,
@@ -384,57 +395,50 @@ PIXI.Sprite.prototype._renderCanvas = function(renderSession)
384395 ( this . anchor . y ) * - frame . height ,
385396 frame . width ,
386397 frame . height ) ;
398+ }
387399 }
388400 else
389401 {
390-
391-
392-
393- if ( texture . trim )
402+ if ( texture . trim )
394403 {
395- var trim = texture . trim ;
396-
397404 context . drawImage ( this . texture . baseTexture . source ,
398- frame . x ,
399- frame . y ,
400- frame . width ,
401- frame . height ,
402- trim . x - this . anchor . x * trim . width ,
403- trim . y - this . anchor . y * trim . height ,
404- frame . width ,
405- frame . height ) ;
405+ crop . x ,
406+ crop . y ,
407+ crop . width ,
408+ crop . height ,
409+ texture . trim . x - this . anchor . x * texture . trim . width ,
410+ texture . trim . y - this . anchor . y * texture . trim . height ,
411+ crop . width ,
412+ crop . height ) ;
406413 }
407414 else
408415 {
409-
410416 context . drawImage ( this . texture . baseTexture . source ,
411- frame . x ,
412- frame . y ,
413- frame . width ,
414- frame . height ,
415- ( this . anchor . x ) * - frame . width ,
416- ( this . anchor . y ) * - frame . height ,
417- frame . width ,
418- frame . height ) ;
417+ crop . x ,
418+ crop . y ,
419+ crop . width ,
420+ crop . height ,
421+ this . anchor . x * - frame . width ,
422+ this . anchor . y * - frame . height ,
423+ crop . width ,
424+ crop . height ) ;
419425 }
420-
421426 }
422427 }
423428
424429 // OVERWRITE
425- for ( var i = 0 , j = this . children . length ; i < j ; i ++ )
430+ for ( var i = 0 , j = this . children . length ; i < j ; i ++ )
426431 {
427432 var child = this . children [ i ] ;
428433 child . _renderCanvas ( renderSession ) ;
429434 }
430435
431- if ( this . _mask )
436+ if ( this . _mask )
432437 {
433438 renderSession . maskManager . popMask ( renderSession . context ) ;
434439 }
435440} ;
436441
437-
438442// some helper functions..
439443
440444/**
0 commit comments