hallo.
i have a enemy creation function and inseit it an collision handler.
now i tryed to put in an splash effect, means, if object1 and 2 collide, an splash should appear and disappear slowly.
the splash appears perfectly, it disappears even faster and faster in time and sometimes its still there and does not disappear.
ther is the full enemyspawn code, beneath just the splash code
function creategegnerZA() -- Determine the enemies starting position 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 --Start the bad guy according to starting position gegnerZA[gegnerZAZahl] = display.newImage("zombieeye.png") gegnerZA[gegnerZAZahl].x = startingX gegnerZA[gegnerZAZahl].y = startingY physics.addBody(gegnerZA[gegnerZAZahl], "dynamic", { isSensor=true, radius=90} ) gegnerZA[gegnerZAZahl].name = "gegnerZA" sceneGroup:insert(gegnerZA[gegnerZAZahl]) --rotation:: angle = math.deg(math.atan2((soldat.y-gegnerZA[gegnerZAZahl].y),(soldat.x-gegnerZA[gegnerZAZahl].x))) gegnerZA[gegnerZAZahl].rotation = angle +90 -- Then move the bad guy towards the center of the screen. Once the transition is done, remove the bad guy. gegnerZA[gegnerZAZahl].trans = transition.to(gegnerZA[gegnerZAZahl], { time=gegnerZASpeed, x=halfW, y=halfH, onComplete = function (self) self.parent:remove(self); self = nil; -- Since the bad guy has reached the monkey, we will want to remove a banana display.remove(leben[anzahlLeben]) anzahlLeben = anzahlLeben - 1 gegnerZAZahl = gegnerZAZahl -- If the numbers of lives reaches 0 or less, it's game over! if(anzahlLeben \<= 0) then timer.cancel(tmr\_creategegnerZA) bg:removeEventListener("touch", touched) local txt\_gameover = display.newText("Game Over!",0,0,native.systemFont,90) txt\_gameover.x = halfW txt\_gameover.y = screenH \* 0.3 sceneGroup:insert(txt\_gameover) --txt\_gameover = display.newText("Return To Menu",0,0,native.systemFont,32) -- local txt\_gameover2 = display.newImage("endlessbtn.png") local txt\_gameover2 = widget.newButton { defaultFile = "homebtn.png", label= "bla", onEvent = onGameOverTouch } txt\_gameover2.anchorX = 0.5 txt\_gameover2.anchorY = 0.5 txt\_gameover2.x = halfW txt\_gameover2.y = screenH \* 0.7 --txt\_gameover2:addEventListener("tap", onGameOverTouch) verlaufg:insert(txt\_gameover2) end end; }) gegnerZAZahl = gegnerZAZahl + 1 end tmr\_creategegnerZA = timer.performWithDelay(gegnerZASpawnSpeed, creategegnerZA, -1) function onCollision( event ) if(event.object1.name == "gegnerZA" and event.object2.name == "bullet" or event.object1.name == "bullet" and event.object2.name == "gegnerZA") then -- Update the score score = score + 1 scoreTxt.text = ""..score --winning screen if(score == -1) then timer.cancel(tmr\_creategegnerZA) bg:removeEventListener("touch", touched) local spielvorbei = widget.newButton { defaultFile = "homebtn.png", label= "endlesssssssssssss", onEvent = onGameOverTouch } spielvorbei.x = \_W/2 spielvorbei.y = \_H/2 spielvorbei.anchorX = 0.5 spielvorbei.anchorY = 0.5 group2:insert(spielvorbei) end -- Make the objects invisible event.object1.alpha = 0 event.object2.alpha = 0 local midX = ( event.object1.x + event.object2.x ) \* 0.5 local midY = ( event.object1.y + event.object2.y ) \* 0.5 splashZA = display.newImage("zeyesplash.png") splashZA.anchorX = 0.5 splashZA.anchorY = 0.5 splashZA.y = midY splashZA.x = midX splashZA.alpha = 0.7 splashZA.rotation = soldat.rotation sceneGroup:insert(splashZA) local function alphatimer() splashZA.alpha = splashZA.alpha - 0.0001 if splashZA.alpha == 0 then --splashZA.alpha = nil end return true end Runtime:addEventListener("enterFrame", alphatimer) sceneGroup:insert(lichtkranz) sceneGroup:insert(soldat) -- Cancel the transitions on the object transition.cancel(event.object1.trans) transition.cancel(event.object2.trans) -- Then remove the object after 1 cycle. Never remove display objects in the middle of collision detection. local function removeObjects() display.remove(event.object1) display.remove(event.object2) end timer.performWithDelay(1, removeObjects, 1) end end
just the code
local midX = ( event.object1.x + event.object2.x ) \* 0.5 local midY = ( event.object1.y + event.object2.y ) \* 0.5 splashZA = display.newImage("zeyesplash.png") splashZA.anchorX = 0.5 splashZA.anchorY = 0.5 splashZA.y = midY splashZA.x = midX splashZA.alpha = 0.7 splashZA.rotation = soldat.rotation sceneGroup:insert(splashZA) local function alphatimer() splashZA.alpha = splashZA.alpha - 0.0001 if splashZA.alpha == 0 then --splashZA.alpha = nil end return true end Runtime:addEventListener("enterFrame", alphatimer)
thank you