简体   繁体   中英

How to make a specific physics body in a moving animation in corona sdk?

I have a moving animation called "instance1" which has 8 frames in my corona sdk game. Unfortunately the dynamic physics body I try to add picks up the transparent space in the rest of the animation and when instance1 jumps on to a platform it just goes off of the screen because of the transparent space. Is there a way to set a physics body to the current frame's opaque colour only? Here is the code:

local sheet1 = graphics.newImageSheet( "runningcat.png", { width=496, height=206.5, numFrames=8 } )
local instance1 = display.newSprite( sheet1, { name="cat", start=1, count=8, time=1000 } )
instance1.x = display.contentWidth / 4 + 10
instance1.y = baseline - 100
instance1.xScale = .3
instance1.yScale = .3
instance1:play()
physics.addBody( instance1, { density=3.0, friction=0.5, bounce=0.3 } )

Any help appreciated.

Mitra0000

If you don't define, the body will create with a square equals to you image. Try to set body vertices to make it work exactly what you want

local pentagonShape = { 0,-37, 37,-10, 23,34, -23,34, -37,-10 }

physics.addBody( pentagon, { density=3.0, friction=0.8, bounce=0.3,   shape=pentagonShape } )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM