How to measure variance in sprite animation height?

I’m wondering if anyone knows how I can measure the variance of the height of each sprite animation frame so that I can use the result to pop a head on top of an animated body and inherit the bounce.
I want to have the head aiming where my finger is on the screen hence the need for a seperate head.

so the resulting equation for y would be something like:

head.y = sprite.centerY+(sprite.height*.5) per frame

Is this possible?

Cheers

chris [import]uid: 9457 topic_id: 3341 reply_id: 303341[/import]

Is there really noone able to help me out with this one?? [import]uid: 9457 topic_id: 3341 reply_id: 10068[/import]

(mainly pseudocode)

in your scene module (main or whatever) prepare a frame-heigh table :

[lua]local sData=require(“bodySheet”).getSpriteSheetData()
hTable={}

–iterate bodySheet.lua data file and collect the frames height
for i,v in ipairs(sData.frames) do
frameHeight=sData.frames[i].textureRect.height
hTable[i]=frameHeight
end [/lua]

In enterFrame listener:

[lua]frame=sprite:currentFrame --I don’t know what this returns (not on a mac now)

spriteFrameHeight = hTable[frame] --or something similar

head.y=sprite.centerY+(spriteFrameHeight*.5) [/lua]

Also, to save you from some hours of meaningless brain-torturing:
For the head, you will need to set reference point to “bottomcenter”. However, have in mind that there is a known bug concerning spritesheets + referencePoint usage. So, just handle the head with the default “center” reference Point. [import]uid: 7356 topic_id: 3341 reply_id: 10077[/import]

If you are using animations with Sprite Sheets (non-uniformly sized images), simply call MySprite.width or MySprite.height while animating to get the actual height or width of the current frame displayed (note: they always return the ORIGINAL width and height of the current frame, no matter if the Sprite has been scaled -this is a bit weird).

If you created your Sprite Sheet with Zwoptex, for example, all image frames can be trimmed (geting rid of the transparent area around your character). So .width and .height actually return the width and height of your character (of the currently displayed animation frame). [import]uid: 9644 topic_id: 3341 reply_id: 10107[/import]

Hi Mau Mau, could you show me what you mean?
[import]uid: 9457 topic_id: 3341 reply_id: 10141[/import]

Get a series of images and import them into Zwoptex (the image packing tool).

Make sure you checked the “trim images” option there. This will remove the transparent (empty) space around every image. All images will then be placed on a single texture with optimal usage of the available space.

Then you export the combined image file and a data sheet. Corona reads this data sheet to know where to find “Frame1” of your animation on that texture, “Frame2” and so on. This data sheet also tells Corona the width and height of every frame on that texture. Remember, you checked the “trim images” option in Zwoptex, so each frame can be of a different size.

Well, if you load such a Sprite Sheet into Corona and animate it, you can detect the actual width and height of the currently shown animation frame of the sprite simply by using MySprite.width and MySprite.height.

Here is a good explanation of sprite sheets:
http://developer.anscamobile.com/content/game-edition-sprite-sheets
So in short: if you want to easily detect the current width and height of an animation frame, you should use sprite sheet animations.

[import]uid: 9644 topic_id: 3341 reply_id: 10145[/import]

Thanks for your help guy’s.
MauMau I went for your method as it made it rather simple.
This is what I came up with. I’m sure one of you could refine this for us but it’s doing the job for me :slight_smile:

In Main:
[lua] – Cranks Head
local crankHead = display.newImageRect(“images/crankhead.png”,55,54)
playerGroup:insert(crankHead)
–set pivot point for head for both positioning and rotation
crankHead:setReferencePoint( display.BottomCenterReferencePoint )[/lua]

In Runtime event listener:
[lua] – Animate Bounce for anything attached to Crank
local spriteWidth = crank.width
local spriteHeight = crank.height

– Bounce in x
crankArm.x = crank.x - ( spriteWidth * .15)
crankHead.x = (crank.x * 1.1)- ( spriteWidth * .1)
print ("spriteWidth: " … spriteWidth )
print ("armX: " … crankArm.x )

– Bounce in Y
crankArm.y = ( crank.y * 1.1 )- ( spriteHeight * .5)
crankHead.y = ( crank.y * 1.11 ) - ( spriteHeight * .5 )
print ( "spriteHeight: " … spriteHeight )
print ( "armY: " … crankArm.y )[/lua]

I hope this helps others too.

Cheers
Chris [import]uid: 9457 topic_id: 3341 reply_id: 10232[/import]