Easier way to define x, y, width, height for a lot of sprites

**UPDATED TO CORRECT ERROR ON MY PART**  

Tip 2: All of the images for a particular animation sequence MUST be the same dimension.

i.e. If you have 5 images for a ‘run’ sequence, all 5 of the original discrete image MUST be of the same dimension.

If your assets come otherwise they won’t work without a lot of effort.

I have never run across a paid set of assets that don’t conform to these requirements.

Texture packer will take these ‘same sized source images’ and pack them in a sheet with just enough room to later pull them out, while fitting together very tightly.

Are those PZUH assets?  If so, did they come in a single  big sheet or as discrete images?

You can answer all my questions later.  PM me first  I gotta roll soon.

-Ed

I am aware.

PM sent.

Also, the images are discrete, and they are from gameart2d.com

Not sure what PZUH is…

The frames are different sizes because of the different positions of the characters. A person standing is not as wide as a person lying on the floor.

I’ll give these a look, but just some I’m clear…

The GOAL is to be able to:

  1. Use these images to make a sprite

  2. Be able to play any animation sequence.

  3. Be able to swap between sequences without needing to destroy and remake the sprite

Right?

Oh, pzuh is gameart2d…

Yes, that is correct.

Corona doesn’t support “removal of whitespace” that texture packer does so you will need to uncheck that option to ensure every frame is the same dimension.

The free art sprite you have downloaded won’t work as is in Corona without manually modifying it.

  1. I gave you some bad advice,  the sizes of the different sequences don’t have to be the same.

  2. I’m not clear what trouble you’re having.  I dropped them on texture packer, produced a sheet, then used the following code to show the sprites and swap animations w/o an issue:

I’ll PM you my code shortly.

-- ============================================================= -- Copyright Roaming Gamer, LLC. 2009-2015 -- ============================================================= -- main.lua -- ============================================================= --require "ssk2.loadSSK" --\_G.ssk.init( ) local centerX = display.contentCenterX local centerY = display.contentCenterY local function run( source, x, y ) local info = require( source .. ".demo") local sheet = graphics.newImageSheet( source .."/demo.png", info:getSheet() ) local sequenceData = { { name = "idle", start = info:getFrameIndex("Idle\_\_000"), count = 10, time = 1000, loopCount = 0, }, { name = "dead", start = info:getFrameIndex("Dead\_\_000"), count = 10, time = 1000, loopCount = 0, }, { name = "climb", start = info:getFrameIndex("Climb\_\_000"), count = 10, time = 1000, loopCount = 0, }, } local anim = display.newSprite( sheet, sequenceData ) anim.x = x anim.y = y anim:play() anim:scale(2,2) -- Swap sequences in a loop forever -- local curAnim = 1 local animNames = { "idle", "climb", "dead" } timer.performWithDelay( 2000, function() anim:pause() curAnim = curAnim + 1 if( curAnim \> #animNames ) then curAnim = 1 end anim:setSequence( animNames[curAnim] ) anim:play() end, -1 ) end run("orig", centerX, centerY)

Note: PZUH is an artist.

OOPs… saw your response.  I’m a bit out of sync.

Thanks, @roaminggamer, the PMed project was everything I was looking for.

I’m not sure if that’s only an issue with the resulting files created using TexturePacker but in general Corona does support the required offsetting for sprite frames. It’s defined by the sourceX, sourceY, sourceWidth and sourceHeight entries of a frame.

Here’s how it looks for a simple rotating coin where each source frame was 32x32 pixels (it’s created using my own image packing tool)

    frames =     {         { -- 1) SPR\_COIN\_00             x = 125,             y = 146,             width = 18,             height = 30,             sourceX = 6,             sourceY = 0,             sourceWidth = 32,             sourceHeight = 32,         },         { -- 2) SPR\_COIN\_01             x = 651,             y = 123,             width = 30,             height = 30,             sourceX = 0,             sourceY = 0,             sourceWidth = 32,             sourceHeight = 32,         },         { -- 3) SPR\_COIN\_02             x = 124,             y = 225,             width = 18,             height = 30,             sourceX = 6,             sourceY = 0,             sourceWidth = 32,             sourceHeight = 32,         },         { -- 4) SPR\_COIN\_03             x = 124,             y = 266,             width = 10,             height = 30,             sourceX = 10,             sourceY = 0,             sourceWidth = 32,             sourceHeight = 32,         },

Yes, but to do this for 110 sprites, it would have taken a while. And I have multiple characters.