Hey Guys,
I have a problem with spwaning display.newCirlce… physics.addBody -
Structure of my script.
-
Display all objects with Physics.addbody - radius.
2. Local function onCollision(event) - for collision detection
3. Runtime:addEventListener(“collision”, onCollision) -
- 3 objects are there = physics.addBody = true
1 object = egg1 (rect)
2 object = egg2 (Circle)
3 object = egg3 (Circle)
- 3 objects are there = physics.addBody = true
X object = Player
X Object must hit all 3 objects with one touch event to win. If X object collides with 1-2 objects they disappear.
if not win then automatically I let respwan the Hit objects egg1,egg2 and egg3, becuase the Objective is to Hit all Elements with 1 touch event.
While Doing this respawn all objects everything Works fine with display.newRects. BUT the display.newCirlce objetcs somehow they have physics.addBody and they Collide with (X object = Player ), HOWEVER the detection in Runtime:addEventListener(“collision”, onCollision) the [#2. Local function onCollision(event) - for collision detection] does not work anymore…
I do not why. Could you help me with this?
Short code here…
WITH function _reCreate( ) I call to respawn egg1,egg2,egg3 … display.Rects are working. Display.new Circle unfortunately not … Please help. Thanks in advance …
Sry for typos, if the written down does not convey clear the problem please let me know.
Best regs
function createEgg3() schlossZetra3 = false egg3 = display.newCircle(\_CX+50, \_CY-100, 40 ) egg3.alpha=0.1 egg3.id = "egg3" function egg3Physics( ) if ( event.phase == "ended" ) then physics.addBody( egg3, "static", { density=1.0, friction=0.3, bounce=0.2,radius=35, } ) egg3.isSensor = true -- transMenu3 = transition.to( egg3, { xScale=1, yScale=1, time=300, transition=easing.outBack} ) end end transMegg3 = transition.to( egg3, { alpha=1, xScale=1, yScale=1, time=750, transition=easing.outElastic,onComplete=egg3Physics} ) -- print("h31\_@") end createEgg1() ... After some scripts ... local function onCollision(event) local function removeOnBirdy3(obj1, obj2) schlossZetra3 = true function disappearBird3() if ( event.phase == "began" ) then -- physics.removeBody( egg3 ) display.remove(egg3) -- transition.scaleTo( egg3, { time=1, alpha=0, xScale=4.0, yScale=4.0} ) end end timer.performWithDelay( 1, disappearBird3 ) end local function \_reCreate( event ) display.remove(proj) if (callWinMia == false) then if ( schlossZetra1 == true) then schlossZetra1 = false createEgg1() end if ( schlossZetra2 == true ) then schlossZetra2 = false createEgg2() end if ( schlossZetra3 == true ) then schlossZetra3 = false createEgg3() end -- Runtime:addEventListener( "touch", screenTouch ) end return true end if (event.object1.id == "egg1" and event.object2.id == "proj") then callWin () removeOnBirdy() print("1xI ") elseif (event.object1.id == "egg2" and event.object2.id == "proj") then callWin () removeOnBirdy2() print("2xI ") elseif (event.object1.id == "egg3" and event.object2.id == "proj") then callWin () schlossZetra3 = true display.remove(egg3) elseif (event.object1.id == "deadBorder" and event.object2.id == "proj") then \_reCreate() print("4xI \_reCreate") end return true end Runtime:addEventListener("collision", onCollision) end