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]
–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
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]
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.
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
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