Search Unity

SpritePacker and sprite boundaries

Discussion in '2D' started by RavenTravelStudios, May 21, 2016.

  1. RavenTravelStudios

    RavenTravelStudios

    Joined:
    Oct 15, 2015
    Posts:
    100
    Hi,

    i have a spritesheet like this:

    upload_2016-5-21_18-10-38.png

    I pack the spritesheet in atlas like this:

    upload_2016-5-21_18-11-19.png


    As you can see, the rect boundaries of the sprite are messed up by the atlas.
    I was expecting something like this:

    upload_2016-5-21_18-21-41.png

    I edited the image to show you... the gap, the right padding from left bound, is gone when Unity packs the sprite.

    What i need is to get the single spriteSheet and slice it by code at runtime basing on his rect canvas.

    Something like:

    for (int c = 0; c < numFrames; c++)
    {
    spriteArray[c] = Sprite.Create(atlasTexture, new Rect((int)sourceSprite.textureRect.x + (c * h), (int)sourceSprite.textureRect.y, h, h), origin, 1);
    }

    sourceSprite.textureRect.x, y is the sprite coord inside the atlas
    h is the frame size of the sprite (for example, a 256x256 frame in a 6 frames spritesheet will result in the 1536x256 texture)

    Can i pack and retrieve the exact original bounds? Seems this is due to the blend made by the packer which wants to trim and overlay some room occupied by alpha channel.
     
    Last edited: May 21, 2016
  2. RavenTravelStudios

    RavenTravelStudios

    Joined:
    Oct 15, 2015
    Posts:
    100
    Solved, i had to set the texture as full rect in the importer.

    upload_2016-5-22_14-48-40.png
     
    theANMATOR2b likes this.