Hello.
i have this function at scene:show:
function scene:show( event ) local sceneGroup = self.view local sceneGroup2 = self.view local phase = event.phase if ( phase == "will" ) then physics.start() elseif ( phase == "did" ) then soldatf(event) bg:addEventListener("touch", soldatf) Runtime:addEventListener("touch", bulletf) function cZA() gZA = display.newImage("zombieeye.png") gZA:addEventListener ("touch", killZA ) local startingPosition = math.random(1,4) if(startingPosition == 1) then -- Send bad guy from left side of the screen startingX = -10 startingY = math.random(0,screenH) elseif(startingPosition == 2) then -- Send bad guy from right side of the screen startingX = screenW + 10 startingY = math.random(0,screenH) elseif(startingPosition == 3) then -- Send bad guy from the top of the screen startingX = math.random(0,screenW) startingY = -10 else -- Send bad guy from the bototm of the screen startingX = math.random(0,\_H) startingY = \_H + 10 end gZA.x = startingX gZA.y = startingY gZA.name = "gegnerZA" physics.addBody(gZA, "static", {density = 1, friction=1, bounce=50, radius=70}) sceneGroup2:insert(gZA) local angle = math.deg(math.atan2((soldat.y-gZA.y),(soldat.x-gZA.x))) gZA.rotation = angle + 90 gZA.trans = transition.to(gZA, {time=gegnerZASpeed, x=soldat.x, y=soldat.y, rotation = angle+90, onComplete=hitSoldat}) sceneGroup:insert(soldat) end function hitSoldat(self) display.remove(self) anzahlLeben = anzahlLeben-1 end function killZA(event) local obj = event.target display.remove(obj) transition.cancel ( event.target.trans ) if anzahlLeben \>0 then -- cZA() end splashZA = display.newImage("zeyesplash.png") splashZA.alpha = 1 splashZA.x = event.x splashZA.y = event.y --angle = math.deg(math.atan2((event.y-event.target.y),(event.x-event.target.x))) --splashZA.rotation = angle +90 splashZA.rotation = event.target.rotation - 180 sceneGroup:insert(splashZA) local trans = transition.to(splashZA, {time=2000, alpha=0, onComplete=nil}) return Object end tmr\_creategegnerZA = timer.performWithDelay(gegnerZASpawnSpeed, cZA, 1) composer:showOverlay("schatten") end end
this function should call an enemy and let it walk (transition) to the soldat position.
im calling this function with the timer at the end.
my problem is,there appears 2 enemys. if i change timers “1” into 2, the double, 4 enemys appears.
i now, the scene:show will call two times, but two times “did” and two times “will”?
how can i fix it?