Physics body with sprite sheet animation

Hai, I have to create physics body with sprite animation, My code is

local function stumpAnimation() 

    local grpStump = display.newGroup()

    spriteStump = display.newSprite( stumpImageSheet , {frames={1,2,3,4,5,6,7,8,9,10,11},  time=1000, loopCount=0 } ) 

    spriteStump.x=  240

    spriteStump.y=  480

    grpStump:insert( spriteStump )

    spriteStump:play()

    physics.addBody( grpStump, “static”, { density=3.0, friction=0.0, bounce=0.0 } )

end

stumpAnimation() 

My problem is i see only animation not body in debug mode, but when i change the body static to dynamic that body falls down. No collision with another body.

Hi @kripa1415,

You’re trying to add a physics body to the display group"grpStump()". This isn’t allowed… you must add it to the sprite “spriteStump”, and perhaps add bodies to other objects in the group individually. If you want one body to represent a large area (like, span over many stumps), you’ll need to create another body (multi-shape, possibly) on an invisible object and place that in the group.

As for “static”, those bodies will not be affected by gravity or other physical forces. This is why they’re good for walls and other static, stationary objects. However, in any collision, at least one body must be “dynamic” (or both of them)… you will not receive collisions between a “static” and “kinematic” body, for example. If you need your stumps to be dynamic (for collision sensing) but unaffected by gravity, you can use the following property to turn off gravity on the single object:

http://docs.coronalabs.com/api/type/Body/gravityScale.html

Hope this helps,

Brent

Hi @kripa1415,

You’re trying to add a physics body to the display group"grpStump()". This isn’t allowed… you must add it to the sprite “spriteStump”, and perhaps add bodies to other objects in the group individually. If you want one body to represent a large area (like, span over many stumps), you’ll need to create another body (multi-shape, possibly) on an invisible object and place that in the group.

As for “static”, those bodies will not be affected by gravity or other physical forces. This is why they’re good for walls and other static, stationary objects. However, in any collision, at least one body must be “dynamic” (or both of them)… you will not receive collisions between a “static” and “kinematic” body, for example. If you need your stumps to be dynamic (for collision sensing) but unaffected by gravity, you can use the following property to turn off gravity on the single object:

http://docs.coronalabs.com/api/type/Body/gravityScale.html

Hope this helps,

Brent