some how when the first time object one and object 2 collide instead displaying first text “you won” i get the second text on display " Game over …"
this only happen only first time when they collide rest works fine … don’t no why this happening but i need your help
code below :
[lua]ocal function onGlobalCollision( event )
if ( event.phase == “began” ) then
if (event.object1.myName == “happy” and event.object2.myName== “cake”) then
local textW = display.newText(“You Won”, display.contentCenterX, display.contentCenterY, native.systemFontBold, 50)
textW:setTextColor(230, 250, 0)
happy:removeSelf()
cake:removeSelf()
– end
timer.performWithDelay(1000, function() textW:removeSelf(); text = nil; cake = nil end)
timer.performWithDelay(1100, function()
createHappy();
createCake();
–moveCake()
angry.x = 880
angry.y = 600
angry2.x = 830
angry2.y = 520
cake.x = 730
cake.y = 420
end)
else
local text = display.newText(“Game Over! Try Again.”, display.contentCenterX, display.contentCenterY, native.systemFontBold, 50)
text:setTextColor(0, 250, 260)
–grp:insert(text)
–grp:insert(textW)
scoreTxt.alpha = 0
score = 0
scoreTxt.text = "score: "…score
happy:removeSelf()
cake:removeSelf()
timer.performWithDelay(1000, function() text:removeSelf(); text = nil; cake = nil end)
timer.performWithDelay(1100, function()
–reset things after the collision
–scoreTxt.text = "score: "…score
createHappy();
createCake();
–moveCake()
angry.x = 880
angry.y = 600
angry2.x = 830
angry2.y = 520
cake.x = 330
cake.y = 420
end)
end
end
end
Runtime:addEventListener(“collision”, onGlobalCollision)[/lua]