Jump to content

bug found when using trimmed sprite atlas


stupot
 Share

Recommended Posts

I am using Version Phaser 2.1.1 and I have used texture atlas's created by both TexturePacker and ShoeBox.

 

I've noticed a display glitch when animating a sprite from a trimmed sprite atlas.  In my case the glitch was that the displayed sprite jumped 2 pixels down from about halfway through the animation.

 

My sprite atlas consists of an animation that starts smaller than the frame and reaches the fullframe size halhway through and maintains fullframe size until the end of the animation.

 

On inspection it was found that the glitch occurs on the transition from a trimmed frame to a frame that is full sized and it was found in the phaser code that the texture.trim values are not cleared, thus a fullframe that was preceded by a trimmed frame will still use the trimmed frame trim xy offsets, and get drawn in the wrong place.

 

In Phaser.Sprite.prototype.setFrame() I simply added an else chunk to remove the trim properties from the texture if !frame.trimmed, which fixed my problem, as follows:

if (frame.trimmed) {    ...                         // existing code}else {    this.texture.trim = null;   // new code}

I haven't attempted a github pull request as this may not be the best way of fixing the problem and the fix may be required in the other setFrame functions so really needs looking at by someone more familiar with the phaser internals.

 

 

 

Link to comment
Share on other sites

Yep, that's fixed it.

 

Interesting to see a re-check of the frame.trimmed being false in the else-if when it would only be doing that if it were false anyway (having failed the initial true check). 

else if (!frame.trimmed && this.texture.trim)

Other than to enhance understanding, was this done for any other specific reason?

Link to comment
Share on other sites

  • 1 month later...

I'm having a probably related problem. 

When using a trimmed animation, so sprites are optimized, in an xml atlas made with shoebox, which reports their original dimensions. 

It all works nicely, unless I set the sprite's anchor to (.5,.5), in that case, the animation just jumps all over the place, as I think, anchoring takes into consideration width and height, and those change for each frame, rather than reflecting the original frame's width and height , reported in the xml so:

 

<SubTexture name="00019.png" x="623" y="669" width="184" height="191" frameX="-17" frameY="-83" frameWidth="218" frameHeight="357"/>
Did anyone else here notice this behaviour, or is something wrong on my side?  
 
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...