After you create it.
myCircle1 = display.newCircle(…)
myCircle1.ID = “Circle1”
After you create it.
myCircle1 = display.newCircle(…)
myCircle1.ID = “Circle1”
When Circle1 touch Crash1 there’s nothing happen.
Code:
function endGamelevel1() local endtext1 = display.newText ("You lost!", 160, 50, font, 32) endtext1:setFillColor (0,0,0) timer.cancel(timer1) Runtime:removeEventListener("enterFrame", movelevel1) button1:removeEventListener("tap", tap) myCircle1:removeEventListener("collision", myCircle1) local function restart (event) composer.gotoScene( "restart1" ) end local restartbutton1 = display.newImage("restart.png", 150, 200, 100, 100) restartbutton1:addEventListener( "tap", restart ) end local function Collision(self, event) if (event.phase == "began") then if (self.ID == "Circle1" and event.other.ID == "Crash1") then endGamelevel1 () end end end function scene:create( event ) local physics = require "physics" physics.setGravity( 0, 0 ) myCircle1 = display.newImage( "circle.png", 90, 225, 35 ) myCircle1.ID = "Circle1" physics.addBody( myCircle1, {radius=38.5} ) myCircle1.collision = Collision myGridlvl1 = display.newRect (160, 100, 1000, 22) myGridlvl1:setFillColor (0,0,0) myGrid2lvl1 = display.newRect (160, 350, 1000, 22) myGrid2lvl1:setFillColor (0,0,0) myGridlvl1.ID = "Crash1" myGrid2lvl1.ID = "Crash1" physics.addBody( myGridlvl1, "static") physics.addBody( myGrid2lvl1, "static") end
What is wrong?
print out the values of self.ID and event.other.ID and see if it’s what you expect.
myCircle1.ID = “Circle1”
myGridlvl1.ID = “Crash1”
myGrid2lvl1.ID = “Crash1”
When myCircle1 touched myGridlvl1 or myGrid2lvl1 then nothing happens. After touch It should be actived endGamelevel1 ().
Let me re-ask the question. Inside the collision handing function, what are the values of “self.ID” and “event.other.ID”. You need to make sure self is what you think it is and what event.other.ID is.
Rob
In my other project the same code is working, maybe because I don’t use scene:create or something.
EDIT: In my opinion everything is OK. Do you know how I can do that in another way?
Do you know how I can do that in another way?
Put in print statements. Print out the values of self.ID and event.other.ID. Post those results here so I can see what’s going on.
Rob
Offtopic question:
physics.start() must be at the top or inscene:create or in scene:show?
What I recommend is doing in scene:create();
physics.start()
physics.pause()
This will let you add physics bodies without having them start interacting with themselves. Since scene:create() is not guaranteed to be called when you go to a scene if it’s cached, you would call physics.start() again in scene:show()'s will phase to resume the simulation.
Rob
In the main chunk is:
function endGamelevel1() ... timer.cancel(timer1) ... end
and when function is called then:

What is wrong?
What is line 22 of lvl1.lua?
timer.cancel(timer1)
So ask yourself why is timer1 nil? The likely cause is either it’s out of scope (you defined it in another code block and this block can’t see it). The other likely cause is it’s really nil. Have you already cancelled it? Did you ever create the timer? Are you using timer1 as a different variable.
Rob
I’m stupid. Fixed.
Another problem:
In the main chunk is:
function endGamelevel1() .. button1:removeEventListener("tap", tap) .. end
and in scene:show:
function scene:show( event ) elseif ( phase == "did" ) then ... button1:addEventListener( "tap", tap ) ... end
When function endgamelevel1() is called then:

creating code of button1 is in scene:create
I can’t troubleshoot your whole app for you. Perhaps someone in the community would want to help. Do you have a function named tap? Why would it be nil or different when you try to remove it.
However, you don’t need to remove tap and touch handlers. They remove when the object removes. They can also be added in create. The listeners that you have to do in scene:show() are Runtime listeners, like enterFrame and such.
My question is: Why I can’t button1:removeEventListener( “tap”, tap ) if in scene:show I added: button1:addEventListener( “tap”, tap )?
PS. Thanks for all your help.
Where is button1 defined? Where is the “tap” function defined?
Function “tap” is in the main chunk and button1 is defined in scene:create
Can anybody help?