I used the solution given here and tweaked it a little. My character “Rocco” eats bones. I programmed it so when you touch a particular button the bones go flying into his mouth, which is “mouthEat” in the code. Everything works great, but the final piece to this stage is that when the bones collide with the mouthEat, I want the bones and the mouthEat to disappear, and then have the screen go to the next level. My code below makes sense to me and doesn’t produce any errors. What’s wrong with it?
[lua]
module (…, package.seeall)
function new()
local level1Group = display.newGroup()
local physics = require (“physics”)
physics.start()
physics.setGravity(0,0)
local background = display.newImage( “images/Background1.png”, 0, 0 )
local rocco1 = display.newImage(“images/Rocco1.png”)
local mouthClosed = display.newImage(“images/MouthClosed.png”)
local bone = display.newImage(“images/Bone.png”)
bone.x = 65
bone.y = 25
local bone2 = display.newImage(“images/Bone.png”)
bone2.x = 65
bone2.y = 45
local number1 = display.newImage(“images/1.png”)
number1.x = 85
number1.y = 275
local number2 = display.newImage(“images/2.png”)
number2.x = 185
number2.y = 275
local number3 = display.newImage(“images/3.png”)
number3.x = 285
number3.y = 275
local number4 = display.newImage(“images/4.png”)
number4.x = 385
number4.y = 275
level1Group:insert(background)
level1Group:insert(rocco1)
level1Group:insert(mouthClosed)
level1Group:insert(number1)
level1Group:insert(number2)
level1Group:insert(number3)
level1Group:insert(number4)
level1Group:insert(bone)
level1Group:insert(bone2)
function touchHandler(self, event)
print(“here”)
if (event.phase == “began”) then
transition.to( bone, {time=1000, alpha=1.0, x=259, y=170, onComplete=function() mouthEat.isVisible = true mouthEat.alpha=1.0 end})
transition.to( bone2, {time=1000, alpha=1.0, x=259, y=170})
end
end
number1.touch = touchHandler
number1:addEventListener(“touch”, number1 )
mouthEat = display.newImage(“images/MouthEat.png”)
mouthEat.isVisible = false
physics.addBody (bone, “static”, {bounce=0, density=1.0})
physics.addBody (bone2, “static”, {bounce=0, density=1.0})
physics.addBody (mouthEat, “static”, {bounce=0, density=1.0})
bone.myName = “bone”
bone2.myName = “bone2”
mouthEat.myName = “mouthEat”
– Collision detection!
mouthEat:addEventListener(“collision”, mouthEat)
function mouthEat:collision (event)
if event.other.myName == “bone” then
mouthEat.visible = false
bone2.visible = false
bone.visible = false
director:changeScene(“level2”)
end
end
level1Group:insert(mouthEat)
level1Group:insert(bone)
level1Group:insert(bone2)
return level1Group
end[/lua] [import]uid: 138755 topic_id: 24192 reply_id: 98314[/import]