Is it possible to make spriteSheets into physic bodies or would I have to use a movieClips? If so is it possible to use the physics editor given that the space remain relatively the same? [import]uid: 54716 topic_id: 11359 reply_id: 311359[/import]
Yes, you can apply physics to sprites. I was doing that before eliminating my animation and going to single frame images.
Like many of the questions here, the answer is a few lines of code away… [import]uid: 58455 topic_id: 11359 reply_id: 41224[/import]
Here’s an example that I used (still learning though). You can use physics bodies for the sprites - use physics.setDrawMode(“hybrid”) to see the physics shapes. There’s an example below that shows how you would use a subset of the sprite sheet animation:
[lua] local myObj
local myObjSpriteSheet = sprite.newSpriteSheet(“images/myObjKick30frames.png”,128,128)
local myObjSpriteSet = sprite.newSpriteSet(myObjSpriteSheet, 1, 30)
– ANIM myObj
myObj = sprite.newSprite(myObjSpriteSet)
myObj.x= 100
myObj.y = 160
myObj.isFixedRotation = true
myObjShape = { -20,-50, 20,-50, 20,50, -20,50 }
myObjBody = {density=1,friction=0.2,bounce=0.2,shape=myObjShape}
–myObjBody = {density=1,friction=0.2,bounce=0.2,radius=15}
physics.addBody( myObj, myObjBody)
sprite.add(myObjSpriteSet,“myObj”,1,1,1200,0)
myObj:prepare(“myObj”)
myObj:play()
sprite.add(myObjSpriteSet,“myObjBigKick”,1,18,1200,1)
sprite.add(myObjSpriteSet,“myObjMedKick”,22,9,1200,1)
sprite.add(myObjSpriteSet,“myObjSmallKick”,19,4,1200,1)
sprite.add(myObjSpriteSet,“myObjWalkOnce”,17,6,1200,1)
sprite.add(myObjSpriteSet,“myObjWalkLoop”,17,6,1200,0)
– FUNCTION MAKE myObj KICK
local function onSwipe( event )
if “began” == phase then
kickSize = “small”
myObj:prepare(“myObjSmallKick”)
myObj:play()
end
end
Runtime:addEventListener( “touch”, onSwipe )[/lua] [import]uid: 40033 topic_id: 11359 reply_id: 41237[/import]