[FIXED] trimmed sprite/ImageSheet broken?

Image sheets with different sizes per frame (trimmed) appear squashing and stretching per frame. 

I thought at first it was perhaps that the anchor needed to be reset to 0,0 per sprite. Tried it like this

self.anchorX = 0  

self.anchorY = 0

(and with .5, .5)

Also with and without   graphicsCompatibility = 1

Perhaps it has something to do with the new anchor system, or an issue with getSheet( )  ?

I am curious about this - it *may* (stressing the low possibility though) have something to do with the path being / not being updated properly. Try dumping out the path locations after changing frames - assuming you haven’t done any distortions on the image, all values should be zero - maybe they aren’t?

Thanks Rakoonic-

I attempted to get the x1, x2 etc. values per frame, and I could be wrong here- but sprites don’t have this property. They aren’t on a rect… (which makes me wonder incidentally if they will eventually be so for graphics 2.0…  (filters, distortion, animated normal maps and whatever)). 

I checked  contentWidth and contentHeight for the sprite per frame, and it is changing (matching the width and height values in the SheetInfo.sheet). 

I should also mention that sprites appear fine in non alpha builds (with same code). No odd stretching per frame. 

Hmm I didn’t know that about sprites, I was gonna play with them this weekend. Thanks for trying at least.

Actually I’ll probably still look into it and see if I get the same problem as you.

@roboward: Could you provide a sample that demonstrate your problem? It’d be very helpful in tracking down this problem.

Definitely. This loads a simple low res imagesheet of a spinning cube, with two sticks in front of it. The sticks are completely stationary. In non-alpha builds, you’ll see the sticks remain stationary. In the alpha build, they’ll move towards/away from each other as the image is stretched.

Altering anchor location doesn’t seem to fix it, but I’m guessing it alters the pivot of the distortion. 

In the code I’ve also thrown in a step through of each frame before playing it, with a print out of the imagesheet dimensions per frame. (Can’t access the X1, X2, etc. corners to check those). 

spritesheet:

http://img405.imageshack.us/img405/5000/f3yo.png

Main.lua

[lua]

–main.lua

sheetInfo2 = require(“box”)

imageSheet2 = graphics.newImageSheet ( “box.png”, sheetInfo2:getSheet() ) 

sequenceData2 = 

                    {

                    {name = “forward”, start = 1, count = 12, loopCount = 100, time = 1200}

                    }

anim = display.newSprite( imageSheet2, sequenceData2 )

–anim.anchorX =0

–anim.anchorY =0

anim.x = display.contentWidth * .5

anim.y = display.contentHeight * .5

anim:setSequence(“forward”)

            for i = 1, 9 do   

               anim:setFrame (i)

               print ("x “…anim.contentWidth…” y "…anim.contentHeight)

            end

            anim:play()

             

            print (anim.x1)

[/lua]

And the sheet info (generated with texture packer)

[lua]

–box.lua

local SheetInfo = {}

SheetInfo.sheet =

{

    frames = {

    

        {

            – box_0001

            x=2,

            y=158,

            width=150,

            height=154,

            sourceX = 40,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0002

            x=2,

            y=782,

            width=118,

            height=154,

            sourceX = 53,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0003

            x=284,

            y=314,

            width=128,

            height=154,

            sourceX = 60,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0004

            x=2,

            y=2,

            width=152,

            height=154,

            sourceX = 44,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0005

            x=144,

            y=314,

            width=138,

            height=154,

            sourceX = 46,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0006

            x=154,

            y=158,

            width=144,

            height=154,

            sourceX = 51,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0007

            x=308,

            y=2,

            width=150,

            height=154,

            sourceX = 43,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0008

            x=2,

            y=626,

            width=122,

            height=154,

            sourceX = 52,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0009

            x=2,

            y=470,

            width=124,

            height=154,

            sourceX = 62,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0010

            x=156,

            y=2,

            width=150,

            height=154,

            sourceX = 45,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0011

            x=2,

            y=314,

            width=140,

            height=154,

            sourceX = 44,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0012

            x=300,

            y=158,

            width=140,

            height=154,

            sourceX = 52,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

    },

    

    sheetContentWidth = 512,

    sheetContentHeight = 1024

}

SheetInfo.frameIndex =

{

    [“box_0001”] = 1,

    [“box_0002”] = 2,

    [“box_0003”] = 3,

    [“box_0004”] = 4,

    [“box_0005”] = 5,

    [“box_0006”] = 6,

    [“box_0007”] = 7,

    [“box_0008”] = 8,

    [“box_0009”] = 9,

    [“box_0010”] = 10,

    [“box_0011”] = 11,

    [“box_0012”] = 12,

}

function SheetInfo:getSheet()

    return self.sheet;

end

function SheetInfo:getFrameIndex(name)

    return self.frameIndex[name];

end

return SheetInfo

[/lua]

@roboward: I was able to reproduce and fix the problem using your code. Thank you! The fix will be included in the next Graphics 2.0 update.

Albert, took a look at imagesheets in 2.0 2013.103, and they appear to be working- thanks :slight_smile:

I am curious about this - it *may* (stressing the low possibility though) have something to do with the path being / not being updated properly. Try dumping out the path locations after changing frames - assuming you haven’t done any distortions on the image, all values should be zero - maybe they aren’t?

Thanks Rakoonic-

I attempted to get the x1, x2 etc. values per frame, and I could be wrong here- but sprites don’t have this property. They aren’t on a rect… (which makes me wonder incidentally if they will eventually be so for graphics 2.0…  (filters, distortion, animated normal maps and whatever)). 

I checked  contentWidth and contentHeight for the sprite per frame, and it is changing (matching the width and height values in the SheetInfo.sheet). 

I should also mention that sprites appear fine in non alpha builds (with same code). No odd stretching per frame. 

Hmm I didn’t know that about sprites, I was gonna play with them this weekend. Thanks for trying at least.

Actually I’ll probably still look into it and see if I get the same problem as you.

@roboward: Could you provide a sample that demonstrate your problem? It’d be very helpful in tracking down this problem.

Definitely. This loads a simple low res imagesheet of a spinning cube, with two sticks in front of it. The sticks are completely stationary. In non-alpha builds, you’ll see the sticks remain stationary. In the alpha build, they’ll move towards/away from each other as the image is stretched.

Altering anchor location doesn’t seem to fix it, but I’m guessing it alters the pivot of the distortion. 

In the code I’ve also thrown in a step through of each frame before playing it, with a print out of the imagesheet dimensions per frame. (Can’t access the X1, X2, etc. corners to check those). 

spritesheet:

http://img405.imageshack.us/img405/5000/f3yo.png

Main.lua

[lua]

–main.lua

sheetInfo2 = require(“box”)

imageSheet2 = graphics.newImageSheet ( “box.png”, sheetInfo2:getSheet() ) 

sequenceData2 = 

                    {

                    {name = “forward”, start = 1, count = 12, loopCount = 100, time = 1200}

                    }

anim = display.newSprite( imageSheet2, sequenceData2 )

–anim.anchorX =0

–anim.anchorY =0

anim.x = display.contentWidth * .5

anim.y = display.contentHeight * .5

anim:setSequence(“forward”)

            for i = 1, 9 do   

               anim:setFrame (i)

               print ("x “…anim.contentWidth…” y "…anim.contentHeight)

            end

            anim:play()

             

            print (anim.x1)

[/lua]

And the sheet info (generated with texture packer)

[lua]

–box.lua

local SheetInfo = {}

SheetInfo.sheet =

{

    frames = {

    

        {

            – box_0001

            x=2,

            y=158,

            width=150,

            height=154,

            sourceX = 40,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0002

            x=2,

            y=782,

            width=118,

            height=154,

            sourceX = 53,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0003

            x=284,

            y=314,

            width=128,

            height=154,

            sourceX = 60,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0004

            x=2,

            y=2,

            width=152,

            height=154,

            sourceX = 44,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0005

            x=144,

            y=314,

            width=138,

            height=154,

            sourceX = 46,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0006

            x=154,

            y=158,

            width=144,

            height=154,

            sourceX = 51,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0007

            x=308,

            y=2,

            width=150,

            height=154,

            sourceX = 43,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0008

            x=2,

            y=626,

            width=122,

            height=154,

            sourceX = 52,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0009

            x=2,

            y=470,

            width=124,

            height=154,

            sourceX = 62,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0010

            x=156,

            y=2,

            width=150,

            height=154,

            sourceX = 45,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0011

            x=2,

            y=314,

            width=140,

            height=154,

            sourceX = 44,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

        {

            – box_0012

            x=300,

            y=158,

            width=140,

            height=154,

            sourceX = 52,

            sourceY = 120,

            sourceWidth = 250,

            sourceHeight = 320

        },

    },

    

    sheetContentWidth = 512,

    sheetContentHeight = 1024

}

SheetInfo.frameIndex =

{

    [“box_0001”] = 1,

    [“box_0002”] = 2,

    [“box_0003”] = 3,

    [“box_0004”] = 4,

    [“box_0005”] = 5,

    [“box_0006”] = 6,

    [“box_0007”] = 7,

    [“box_0008”] = 8,

    [“box_0009”] = 9,

    [“box_0010”] = 10,

    [“box_0011”] = 11,

    [“box_0012”] = 12,

}

function SheetInfo:getSheet()

    return self.sheet;

end

function SheetInfo:getFrameIndex(name)

    return self.frameIndex[name];

end

return SheetInfo

[/lua]

@roboward: I was able to reproduce and fix the problem using your code. Thank you! The fix will be included in the next Graphics 2.0 update.

Albert, took a look at imagesheets in 2.0 2013.103, and they appear to be working- thanks :slight_smile: