I have the need for an animated graphic (using a sprite sheet) that represents a “spring”. The spring constantly expands and contracts – the underlying sprite sheet/sequence is performed through a series of images in which the spring is expanding (getting bigger) or contracting. I am able to add the the sprite sheet as a physics body; however, it seems to only add to the engine as the fully “expanded” image or the fully “contracted” image. I would like for the spring to “punch” a character. So, what I’m trying to achieve is for the physics body to actually get smaller or larger along with the changing frames within sprite sheet/animation. I’ve gone so far as to try and add another “hidden” physic object that constant moves back and forth – but it is next to imposible to synch it with the sprite sheet. Any thoughts or recommendations?
Example:
local elementIcon = display.newGroup()
local springSpriteSheet = graphics.newImageSheet(“images/sprites/spring/spring.png”, SpringSpriteSheet:getSheet() )
local springSequence =
{
{ name=“punch”, frames= { 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2 }, time = 700, loopCount = 0 },
}
elementImage = display.newSprite(springSpriteSheet, springSequence )
elementIcon:insert(elementImage)
elementImage:play()
Physics.addBody( elementIcon,
{
density = (element.density or 1.0),
friction = (element.friction or 1.0),
bounce = (element.bounce or 1.0),
isSensor = (element.isSensor or false),
shape = (element.shape or nil),
radius = (element.radius or nil),
filter = (element.filter or nil),
shape = (element.shape or nil),
} )