hello everybody, i got some problem when i set a collision.
my idea is that:
i want that an object, on collision with another, is removed and then another different object is displayed.
the problem start when i want remove also the second object!
how can i write that right?
i'm new in corona and lua so i'm sure there is something that i miss :)
that's my code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | local physics = require("physics") physics.start() physics.setGravity(0,3) local background = display.newImage("sky.png") local grass = display.newImage( "grass.png", true ) grass.x = 160 grass.y = 440 physics.addBody( grass, "static", { friction=0.5, bounce=0.3 } ) grass.myName = "grass" local egg1 = display.newImage("egg.png") egg1.x = 150 egg1.y = 100 egg1.myName = "egg" physics.addBody(egg1, "dinamic",{ density=1.0, friction=0.1, bounce=0.5, radius=25 }) local function eggcrack() eggcrack1 = display.newImage("egg_cracked.png") eggcrack1.x = 100 eggcrack1.y = 100 return true end local function eggckremove(e) if eggcrack1 ~= nil then eggcrack1:removeSelf() end end local function collision(event) if event.other.myName == "grass" then timer.performWithDelay(500, eggckremove, 0) timer.performWithDelay(50, eggcrack, 0) egg1:removeSelf() end end egg1:addEventListener("collision", collision) |
1) at line 16 the spelling should be dynamic
now if you want to remove second object also then you should have to register collision listener for that also or may be runtime listener will be fine
:)
1) tnx!! xD
2) how i can set the collision for that body? i want that when egg1 hit the floor ( "grass" ) egg1 is removed and then is displayed another object the eggcrak. at this point is all ok!
but how can i do if i want that this items is removed after some second? it doesnt collide with anything! create and remove the eggcraked is related only with egg1 collision. is that possible to do?