I am 17 and I am trying to program in Lua. I am trying to make a simple game and I was able to do everything but have the object in the game respawn after it has been destroyed. I was hoping to get some help with it.
Please and thank you!
I am 17 and I am trying to program in Lua. I am trying to make a simple game and I was able to do everything but have the object in the game respawn after it has been destroyed. I was hoping to get some help with it.
Please and thank you!
What condition causes your object to be destroyed?
Do you have your spawn code in its own function?
The condition that causes my object to destroy is a tap and yes my spawn code is in it’s own function
Then after you destroy the touched item, then call your spawn function, perhaps in a timer to give it a little bit time before the new object spawns.
Rob
hello for some reason the second dot doesn’t want to disappear when I tap it
local dot = display.newCircle(display.contentCenterX,display.contentCenterY,100)
local function tp(event)
if event.target:removeSelf() then
local dot = display.newCircle(math.random(0,1080),math.random(0,1920),100)
end
end
dot:addEventListener(“tap”,tp)
timer.performWithDelay( 900, tp ,0 )
i cant remove the second dot
Try:
local dot local tp local function spawnNewDot( thisDot ) if thisDot and thisDot.removeSelf then thisDot:removeSelf() thisDot = nil end dot = display.newCircle(math.random(0,1080),math.random(0,1920),100) dot:addEventListener("tap",tp) end tp = function(event) if event.target then timer.performWithDelay(10, function() spawnNewDot( event.target ) end) end end -- timer.performWithDelay( 900, spawnNewDot , 0 ) spawnNewDot()
Now depending on what you want to do, you can either spawn a new dot each time you touch another dot, or you can spawn them in a timer and just have the tap event remove tapped ones and not respawn.
Rob
thank you a lot
What condition causes your object to be destroyed?
Do you have your spawn code in its own function?
The condition that causes my object to destroy is a tap and yes my spawn code is in it’s own function
Then after you destroy the touched item, then call your spawn function, perhaps in a timer to give it a little bit time before the new object spawns.
Rob
hello for some reason the second dot doesn’t want to disappear when I tap it
local dot = display.newCircle(display.contentCenterX,display.contentCenterY,100)
local function tp(event)
if event.target:removeSelf() then
local dot = display.newCircle(math.random(0,1080),math.random(0,1920),100)
end
end
dot:addEventListener(“tap”,tp)
timer.performWithDelay( 900, tp ,0 )
i cant remove the second dot
Try:
local dot local tp local function spawnNewDot( thisDot ) if thisDot and thisDot.removeSelf then thisDot:removeSelf() thisDot = nil end dot = display.newCircle(math.random(0,1080),math.random(0,1920),100) dot:addEventListener("tap",tp) end tp = function(event) if event.target then timer.performWithDelay(10, function() spawnNewDot( event.target ) end) end end -- timer.performWithDelay( 900, spawnNewDot , 0 ) spawnNewDot()
Now depending on what you want to do, you can either spawn a new dot each time you touch another dot, or you can spawn them in a timer and just have the tap event remove tapped ones and not respawn.
Rob
thank you a lot