Hey Guys, Looking for some help as I’m a little stuck on how to execute the following code properly.
I am trying to establish a “gameOver” function in my game but am having problems 1. removing what appears to be remaining obj’s in my array and #2 the event listeners
Here is my code
--create the BUG's as random images of 3 different BUGS --local bugImages = {"beetle.png", "wasp.png", "bee.png"} --print( bugImages[math.random (#bugImages)] ) --local bug[TotalBugs] = display.newImage(bugImages[math.random (#bugImages)]) bug[TotalBugs] = display.newImage("bee.png", 35,35) --setup tab listener bug[TotalBugs]:addEventListener( "tap", bugKilled ) --setup where bug will spawn bug[TotalBugs].x = startingX bug[TotalBugs].y = startingY --physics.addBody( bug[TotalBugs], "dynamic", { isSensor=true, radius=35} ) bug[TotalBugs].name = "enemyBug" group:insert(bug[TotalBugs]) --move the bugs to the center of the screne --bug[TotalBugs].trans = transition.to(bug[TotalBugs],{ time=2000, x=centerX, y=centerY, onComplete=bugKilled}) bug[TotalBugs].trans = transition.to(bug[TotalBugs], { time=2000, x=centerX, y=centerY, onComplete = function (self) self.parent:remove(self); self = nil; -- Minus lives as has hit center and then determine if lives = 0 if so call activateGameOver() lives = lives - 1 if lives \<= 0 then --timer.cancel(tmr\_createBug) --self:removeEventListener( "tap", bugKilled ) print( "livesOver" ) end end; }) end
Here is the error I get (“screenshot attached”)
Aswell was wondering what the best way would be to load some images as you can see at the start of my function I try to reference a few bugs then when I create them that line dose not appear to work
Any help would be much appreciated guys.