problem with removeScene

hey guys, i have a problem with removing of scenes:

on the menu.lua, if i press the start (endless) button, i get the game scene endless.lua.

on this scene, if i die or win the game, a image appears.

by pressing this image (it´s a widget.newButton) it should led me again back to menu.lua

now, if i press this button, the tap listener appears from menu.lua, but the scene endless.lua wants not remove.

that mean - the screen does not change, the fade effect is not displayed, but the function to call the endless.lua is alive, but without any buttons showing.

i give you a quick view of menu.lua:

tunction timer -\>removeScene(endless) return true local function menu -\> all widget Buttons end function scene:create(event) if did calls the menu() getSceneName "previous" and remove it call the timer function from top end

_____________________________________________

endless function:

first a lot of locals, like: local bg local leftbush local rightbus local topbush local botbush local soldat local lichtkranz etx. function oGameOverTouch() if began gotoScene"menu" end local function showBG function to screens the background and background elements end local function touched the movement logic end local function createenerZA enemy logic end local function verlauf2 a mask and lightnin logic, above everything else include function licht end local function killscore killscore end ----------------- function create:scene call all local function: physics.start() showBG() touched(event) verlauf2(event) creategegnerZA() killsscore() and the listener: bg:addEventListener("touch", touched) Runtime:addEventListener("collision", onCollision) Runtime:addEventListener("touch", licht) tmr\_creategegnerZA = timer.performWithDelay(gegnerZASpawnSpeed, creategegnerZA, -1) end --------------- function scene:show is empty end ------------- function scenehide if will stop listener: physics.stop() bg:removeEventListener("touch", touched) Runtime:removeEventListener("collision", onCollision) Runtime:removeEventListener("touch", licht if did is empty end ---------------- function scene:destroy remove and destroy: group:removeSelf() group = nil display.remove(showBG()) display.remove(touched(event)) display.remove(verlauf2(event)) display.remove(creategegnerZA()) display.remove(killsscore() end

if i include a removeScene(currentScene) function in destroy, the gamelogic will break.

thank you:D

Might i suggest you rethinking your post above.

If you wish for help you need to help yourself.

On looking at your post ( i guess heavily edited) i would make an educated guess that readers will go what on earth is happening, and get lost in the editing mistakes, thus see this as a very long time intensive fix, and the reality is that time would be better spent on their own projects.

The forum is here to help i.e. you see something which you came across and found a fix so it’s easy to pass on the information that lead to the fix.

As it stands at the moment the code you’ve posted IMHO does not let the forum help you.

I don’t mean to offend just trying to help you get an answer.

T.

im very sorry, i thought i post not the whole code because its quite long and skip the uninteresting things, cause i have not problems with a spec. logic or function or what ever, i have issuse with the removements.

but yes you are right, i could done it better :wink:

ill post the whole code later

On re reading your post - i still think more code was needed (don’t know how big it is).

But shot in the dark here is - are you inserting all display objects into the scene group?

T.

thank you first for spending time

is there a difference between normal groups and sceneGroups? if yes then no i didnt,

but, all displayObject are in a group, called “group” and this group i tryed to remove, but take a look yourself:

the code is a bit unclean,

there the whole code.

menu.lua

display.setStatusBar(display.HiddenStatusBar) local \_H = display.contentHeight; local \_W = display.contentWidth; local centerX = display.contentCenterX local centerY = display.contentCenterY local composer = require( "composer" ) local scene = composer.newScene() local widget = require( "widget" ) local sceneGroup = display.newGroup() -- Touch event listener for background image local function timera() composer.removeScene("endless") -- composer.gotoScene( "factory", "fade", 200 ) return true end local function menue(event) --bg-- bgf = display.newImage("tscreenbg.png") bgf.anchorX = 0.5 bgf.anchorY = 0.5 bgf.x = \_W/2 bgf.y = \_H/2 sceneGroup:insert( bgf ) --buttons-- local function onEndlessRelase() composer:gotoScene( "endless", "fade", 500 ) return true end local function onChaptRelase() composer:gotoScene( "endless", "fade", 500 ) return true end local function onCredbtnRelase() composer:gotoScene( "creds", "fade", 500 ) return true end local endlessbtn = widget.newButton { defaultFile = "endlessbtn.png", label = "endlessbtn", onEvent = onEndlessRelase } endlessbtn.anchorX = 0.5 endlessbtn.anchorY = 0.5 endlessbtn.y = \_H/2 + 50 endlessbtn.x = \_W/2 - 55 sceneGroup:insert(endlessbtn) local chapt = widget.newButton { defaultFile = "chaptbtn.png", label = "chapt", onEvent = onChaptRelase } chapt.anchorX = 0.5 chapt.anchorY = 0.5 chapt.y = \_H/2 + 360 chapt.x = \_W/2 - 5 sceneGroup:insert(chapt) local credbtn = widget.newButton { defaultFile = "creditbtn.png", label = "credbtn", onEvent = onCredbtnRelase } credbtn.anchorX = 0.5 credbtn.anchorY = 0.5 credbtn.y = (\_H/2)/0.5 -50 credbtn.x = \_W/2 sceneGroup:insert(credbtn) end function scene:create( event ) local sceneGroup = self.view end function scene:show( event ) local phase = event.phase if "did" == phase then print( "1: show event, phase did by menue" ) menue(event) local currScene = composer.getSceneName( "previous" ) composer.removeScene( currScene ) -- remove previous scene's view composer.removeScene( "factory" ) -- Update Lua memory text display local showMem = function() end memTimer2 = timer.performWithDelay( 2, timera) end end function scene:hide( event ) local phase = event.phase if "will" == phase then -- cancel timer -- timer.cancel( memTimer2 ); memTimer2 = nil; end end function scene:destroy( event ) print( "destroy menu" ) local removeLastScene = composer.getSceneName( "previous" ) composer.removeScene( removeLastScene ) end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

and endless.lua:

display.setStatusBar(display.HiddenStatusBar) local composer = require( "composer" ) local scene = composer.newScene() local screenW, screenH, halfW, halfH = display.contentWidth, display.contentHeight, display.contentWidth/2, display.contentHeight/2 system.activate("multitouch") \_H = display.contentHeight; \_W = display.contentWidth; local centerX = display.contentCenterX local centerY = display.contentCenterY widget = require( "widget" ) local physics = require "physics" ---:::--- local bg local leftbush local rightbus local topbush local botbush local soldat local lichtkranz local lichtkranz2 local scoreTxt local spawnZeit local leben = {} local steine = {} local gegnerZA = {} local gegnerZAZahl = 1 local score = 0 local kills local bulletSpeed = 2 local anzahlLeben = 3 local anzahlSteine = 5 local gegnerZASpeed = 1500 local gegnerZASpawnSpeed = 1000 local rand = math.random() local radiusMax = math.sqrt( centerX\*centerX + centerY\*centerY ) local group = display.newGroup() -----------------------::::::::::::::::::::::::BGSHOW::::::::::::::::::::::-------------- function onGameOverTouch(event) if event.phase == "began" then composer:gotoScene( "menu", "fade", 500 ) end end local function showBG() bg = display.newImage("bg.png") bg.anchorX = 0.5 bg.anchorY = 0.5 bg.y = \_H/2 bg.x = \_W/2 group:insert(bg) for i=1,anzahlSteine do steine[i] = display.newImageRect("stein.png",100+math.random(50) ,100 + math.random(50),2000,200) steine[i].anchorX = 0.5 steine[i].anchorX = 0.5 --steine[i]:scale(rand, rand) steine[i].x = math.random((\_W-100)) steine[i].y = math.random((\_H-100)) angle = math.deg(math.atan2((centerY-steine[i].y),(centerX-steine[i].x))) steine[i].rotation = angle -90 group:insert(steine[i]) end leftbush = display.newImage("leftbush.png") leftbush.anchorY = 0 leftbush.anchorX = 0 leftbush.y = -200 leftbush.x = -65 group:insert(leftbush) rightbush = display.newImage("rightbush.png") rightbush.anchorY = 0 rightbush.anchorX = 0 rightbush.x = 935 group:insert(rightbush) topbush = display.newImage("topbush.png") topbush.anchorY = 0 topbush.anchorX = 0 topbush.y = -60 group:insert(topbush) botbush = display.newImage("botbush.png") botbush.anchorY = 0 botbush.anchorX = 0 botbush.y = 1795 group:insert(botbush) lichtkranz = display.newImage("lichtkranz.png") lichtkranz.y, lichtkranz.x, lichtkranz.anchorX, lichtkranz.anchorY = \_H/2, \_W/2, 0.5, 0.5 lichtkranz.rotation = -90 lichtkranz.alpha = 1 lichtkranz.blendMode = "add" group:insert(lichtkranz) soldat = display.newImage("soldat.png") soldat.x = \_W/2 soldat.y = \_H/2 soldat.rotation = 0 group:insert(soldat) end ---------------------:::::::::::::BG SHOW::::::::::::::::::::---------- ---------------------:::::::::::::touch:::::::::::::::::::::---------- local function touched(event) if(event.phase == "began" or event.phase == "moved") then --soldatrotation angle = math.deg(math.atan2((event.y-soldat.y),(event.x-soldat.x))) soldat.rotation = angle + 90 --lichtkreis um den soldaten wird rotiert angle = math.deg(math.atan2((event.y-lichtkranz.y),(event.x-lichtkranz.x))) lichtkranz.rotation = angle +90 end if (event.phase == "began") then bullet = display.newImage("bullet.png") bullet.x = halfW+30 bullet.y = halfH -20 physics.addBody( bullet, "dynamic", { isSensor=true, radius=20} ) bullet.name = "bullet" group:insert(bullet) -- Find out if we need to fire the bullet to the left or right local farX = screenW\*2 local slope = ((event.yStart-screenH/2)/(event.xStart-screenW/2)) local yInt = event.yStart - (slope\*event.xStart) if(event.xStart \>= screenW/2)then farX = screenW\*2 else farX = screenW-(screenW\*2) end local farY = (slope\*farX)+yInt local xfactor = farX-bullet.x local yfactor = farY-bullet.y local distance = math.sqrt((xfactor\*xfactor) + (yfactor\*yfactor)) bullet.trans = transition.to(bullet, { time=distance/bulletSpeed, y=farY, x=farX, onComplete=nil}) end end local 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" group: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 + 1 -- 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,32) txt\_gameover.x = halfW txt\_gameover.y = screenH \* 0.3 group: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 = "endlessbtn.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) group:insert(txt\_gameover2) end end; }) gegnerZAZahl = gegnerZAZahl + 1 end 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 == 5) then timer.cancel(tmr\_creategegnerZA) bg:removeEventListener("touch", touched) local spielvorbei = widget.newButton { defaultFile = "endlessbtn.png", label= "endlesssssssssssss", onEvent = onGameOverTouch } spielvorbei.x = \_W/2 spielvorbei.y = \_H/2 spielvorbei.anchorX = 0.5 spielvorbei.anchorY = 0.5 end -- Make the objects invisible event.object1.alpha = 0 event.object2.alpha = 0 -- 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 -------------:::::::::::gegnerZa:::::::::--------- --------------::::::::::verlauf::::::::::-------- local function verlauf2 (event) verlauf = display.newImage("verlauf.png") verlauf.x = \_W/2 verlauf.y = \_H/2 verlauf.anchorX, verlauf.anchorY = 0.5, 0.5 verlauf.alpha = 1 local torch = graphics.newMask("alpha3.png") verlauf:setMask(torch) local lichtkranz2 = display.newImage("lichtkranz.png") lichtkranz2.y, lichtkranz2.x, lichtkranz2.anchorX, lichtkranz2.anchorY = \_H/2, \_W/2, 0.5, 0.5 lichtkranz2.blendMode = "add" lichtkranz2.alpha = 0.3 lichtkranz2.isVisible = false local radiusMax = math.sqrt( centerX\*centerX + centerY\*centerY ) function licht (event) verlauf.maskY = event.y -\_H/2 verlauf.maskX = event.x - \_W/2 lichtkranz2.x = event.x lichtkranz2.y = event.y lichtkranz2.Xscale = 0.2 lichtkranz2.isVisible = true --::torcheffect 4 Mask::-- -- Stretch the flashlight as it moves further away -- from the screen's center local radius = math.sqrt( verlauf.maskX\*verlauf.maskX + verlauf.maskY\*verlauf.maskY ) local scaleDelta = radius/radiusMax verlauf.maskScaleX = 1.3 + scaleDelta verlauf.maskScaleY = 1 + 0.2 \* scaleDelta -- Rotate it appropriately about screen center local rotation = math.deg( math.atan2( verlauf.maskY, verlauf.maskX ) ) verlauf.maskRotation = rotation --::torcheffekt4 Mask::-- --::torcheffect4 lichtkranz2::--local radius = math.sqrt( verlauf.maskX\*verlauf.maskX + verlauf.maskY\*verlauf.maskY ) local scaleDelta = radius/radiusMax lichtkranz2.ScaleX = 1 + scaleDelta lichtkranz2.ScaleY = 1 + 0.2 \* scaleDelta -- Rotate it appropriately about screen center local rotation = math.deg( math.atan2( lichtkranz2.y, lichtkranz2.x ) ) lichtkranz2.rotation = rotation -- bg:addEventListener("touch", licht) end end local function killsscore() kills = display.newImage("kills.png") kills.anchorX = 0.5 kills.anchorY = 0.5 kills.x = \_W/2 - 30 kills.y = \_H/25 -- group:insert(kills) scoreTxt = display.newText(""..score,0,0,PWChalk,80) scoreTxt.x = \_W/2 +250 scoreTxt.y = 90 scoreTxt:setTextColor(255, 255, 255) scoreTxt.alpha = 0.5 --group:insert(scoreTxt) ---:::SCORETEXT for i=1, anzahlLeben do leben[i] = display.newImage("leben1.png") leben[i].anchorX = 0.5 leben[i].anchorY = 0.5 leben[i].x = i\*\_W/10-20 leben[i].y = \_H/22 leben[i].alpha = 0.8 --group:insert(leben[i]) end end -- "scene:create()" function scene:create( event ) local group = self.view physics.start() showBG() touched(event) verlauf2(event) creategegnerZA() killsscore() bg:addEventListener("touch", touched) Runtime:addEventListener("collision", onCollision) Runtime:addEventListener("touch", licht) tmr\_creategegnerZA = timer.performWithDelay(gegnerZASpawnSpeed, creategegnerZA, -1) --txt\_gameover2:addEventListener("tap", onGameOverTouch) -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. end -- "scene:show()" function scene:show( event ) local group = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then physics.stop() bg:removeEventListener("touch", touched) Runtime:removeEventListener("collision", onCollision) Runtime:removeEventListener("touch", licht) -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local group = self.view group:removeSelf() group = nil display.remove(showBG()) display.remove(touched(event)) display.remove(verlauf2(event)) display.remove(creategegnerZA()) display.remove(killsscore()) --local currScene = composer.getSceneName( "current" ) --composer.removeScene( currScene ) print("remove zeusch") -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

tank you 

Yes i think your problem is with groups.

1st thing to do is download a fresh copy of the composer template untouched. Use this to compare your composer codes against the std composer code - to my knowledge composer always uses sceneGroup - you have changed a few to group. BUT don’t get confused with the group that you set up -two different things.

composer group is the base - if you don’t insert things in here when you leave a scene things will remain.

But you can also set up sub groups to help with layout design.

    local group = display.newGroup()

is the code to set up sub groups

local sceneGroup = self.view

is the composer group thing

So i think getting an understanding of this will help you on your way - check out the composer tuts as well.

T.

i did it, oh my god, 3 whole free days and now i did it, im so unbelivable happy :slight_smile:

thank you my friend you helped me a lot :wub:

you was right, and not too.

first, i put all the remove calls into the onGameOverTouch function.

after that i had an error, the code:

group:removeSelf()

and

group = nil

is not compartible.

quick fix and lock there, it changes (after removing the composer.removeHidden() function from menu.lua)

i put the objects verlauf, score, leben and lichtkranz2 in a seperat group (because in the normal group, it would gives me some layout problems)

took the group2 into the onGameOverTouch function, set it to remove it self and TADA :wub:

if your interested, there is the code:

display.setStatusBar(display.HiddenStatusBar) local composer = require( "composer" ) local scene = composer.newScene() local screenW, screenH, halfW, halfH = display.contentWidth, display.contentHeight, display.contentWidth/2, display.contentHeight/2 system.activate("multitouch") \_H = display.contentHeight; \_W = display.contentWidth; local centerX = display.contentCenterX local centerY = display.contentCenterY widget = require( "widget" ) local physics = require "physics" ---:::--- local bg local leftbush local rightbus local topbush local botbush local soldat local lichtkranz local lichtkranz2 local scoreTxt local spawnZeit local leben = {} local steine = {} local gegnerZA = {} local gegnerZAZahl = 1 local score = 0 local kills local bulletSpeed = 2 local anzahlLeben = 3 local anzahlSteine = 5 local gegnerZASpeed = 1500 local gegnerZASpawnSpeed = 1000 local rand = math.random() local radiusMax = math.sqrt( centerX\*centerX + centerY\*centerY ) -----------------------::::::::::::::::::::::::BGSHOW::::::::::::::::::::::-------------- local group = display.newGroup() local group2 = display.newGroup() local function showBG() bg = display.newImage("bg.png") bg.anchorX = 0.5 bg.anchorY = 0.5 bg.y = \_H/2 bg.x = \_W/2 group:insert(bg) for i=1,anzahlSteine do steine[i] = display.newImageRect("stein.png",100+math.random(50) ,100 + math.random(50),2000,200) steine[i].anchorX = 0.5 steine[i].anchorX = 0.5 --steine[i]:scale(rand, rand) steine[i].x = math.random((\_W-100)) steine[i].y = math.random((\_H-100)) angle = math.deg(math.atan2((centerY-steine[i].y),(centerX-steine[i].x))) steine[i].rotation = angle -90 group:insert(steine[i]) end leftbush = display.newImage("leftbush.png") leftbush.anchorY = 0 leftbush.anchorX = 0 leftbush.y = -200 leftbush.x = -65 group:insert(leftbush) rightbush = display.newImage("rightbush.png") rightbush.anchorY = 0 rightbush.anchorX = 0 rightbush.x = 935 group:insert(rightbush) topbush = display.newImage("topbush.png") topbush.anchorY = 0 topbush.anchorX = 0 topbush.y = -60 group:insert(topbush) botbush = display.newImage("botbush.png") botbush.anchorY = 0 botbush.anchorX = 0 botbush.y = 1795 group:insert(botbush) lichtkranz = display.newImage("lichtkranz.png") lichtkranz.y, lichtkranz.x, lichtkranz.anchorX, lichtkranz.anchorY = \_H/2, \_W/2, 0.5, 0.5 lichtkranz.rotation = -90 lichtkranz.alpha = 1 lichtkranz.blendMode = "add" group:insert(lichtkranz) soldat = display.newImage("soldat.png") soldat.x = \_W/2 soldat.y = \_H/2 soldat.rotation = 0 group:insert(soldat) end ---------------------:::::::::::::BG SHOW::::::::::::::::::::---------- ---------------------:::::::::::::touch:::::::::::::::::::::---------- local function touched(event) if(event.phase == "began" or event.phase == "moved") then --soldatrotation angle = math.deg(math.atan2((event.y-soldat.y),(event.x-soldat.x))) soldat.rotation = angle + 90 --lichtkreis um den soldaten wird rotiert angle = math.deg(math.atan2((event.y-lichtkranz.y),(event.x-lichtkranz.x))) lichtkranz.rotation = angle +90 end if (event.phase == "began") then bullet = display.newImage("bullet.png") bullet.x = halfW+30 bullet.y = halfH -20 physics.addBody( bullet, "dynamic", { isSensor=true, radius=20} ) bullet.name = "bullet" group:insert(bullet) -- Find out if we need to fire the bullet to the left or right local farX = screenW\*2 local slope = ((event.yStart-screenH/2)/(event.xStart-screenW/2)) local yInt = event.yStart - (slope\*event.xStart) if(event.xStart \>= screenW/2)then farX = screenW\*2 else farX = screenW-(screenW\*2) end local farY = (slope\*farX)+yInt local xfactor = farX-bullet.x local yfactor = farY-bullet.y local distance = math.sqrt((xfactor\*xfactor) + (yfactor\*yfactor)) bullet.trans = transition.to(bullet, { time=distance/bulletSpeed, y=farY, x=farX, onComplete=nil}) end end local 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" group: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 + 1 -- 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,32) txt\_gameover.x = halfW txt\_gameover.y = screenH \* 0.3 group: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 = "endlessbtn.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) group:insert(txt\_gameover2) end end; }) gegnerZAZahl = gegnerZAZahl + 1 end 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 = "endlessbtn.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 -- 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 -------------:::::::::::gegnerZa:::::::::--------- --------------::::::::::verlauf::::::::::-------- local function verlauf2 (event) verlauf = display.newImage("verlauf.png") verlauf.x = \_W/2 verlauf.y = \_H/2 verlauf.anchorX, verlauf.anchorY = 0.5, 0.5 verlauf.alpha = 1 local torch = graphics.newMask("alpha3.png") verlauf:setMask(torch) local lichtkranz2 = display.newImage("lichtkranz.png") lichtkranz2.y, lichtkranz2.x, lichtkranz2.anchorX, lichtkranz2.anchorY = \_H/2, \_W/2, 0.5, 0.5 lichtkranz2.blendMode = "add" lichtkranz2.alpha = 0.5 lichtkranz2.isVisible = false group2:insert(lichtkranz2) group2:insert(lichtkranz) group2:insert(verlauf) group2:insert(soldat) local radiusMax = math.sqrt( centerX\*centerX + centerY\*centerY ) function licht (event) verlauf.maskY = event.y -\_H/2 verlauf.maskX = event.x - \_W/2 lichtkranz2.x = event.x lichtkranz2.y = event.y lichtkranz2.Xscale = 0.2 lichtkranz2.isVisible = true --::torcheffect 4 Mask::-- -- Stretch the flashlight as it moves further away -- from the screen's center local radius = math.sqrt( verlauf.maskX\*verlauf.maskX + verlauf.maskY\*verlauf.maskY ) local scaleDelta = radius/radiusMax verlauf.maskScaleX = 1.3 + scaleDelta verlauf.maskScaleY = 1 + 0.2 \* scaleDelta -- Rotate it appropriately about screen center local rotation = math.deg( math.atan2( verlauf.maskY, verlauf.maskX ) ) verlauf.maskRotation = rotation --::torcheffekt4 Mask::-- --::torcheffect4 lichtkranz2::--local radius = math.sqrt( verlauf.maskX\*verlauf.maskX + verlauf.maskY\*verlauf.maskY ) local scaleDelta = radius/radiusMax lichtkranz2.ScaleX = 1 + scaleDelta lichtkranz2.ScaleY = 1 + 0.2 \* scaleDelta -- Rotate it appropriately about screen center local rotation = math.deg( math.atan2( lichtkranz2.y, lichtkranz2.x ) ) lichtkranz2.rotation = rotation -- bg:addEventListener("touch", licht) end end local function killsscore() kills = display.newImage("kills.png") kills.anchorX = 0.5 kills.anchorY = 0.5 kills.x = \_W/2 - 30 kills.y = \_H/25 group2:insert(kills) scoreTxt = display.newText(""..score,0,0,PWChalk,80) scoreTxt.x = \_W/2 +250 scoreTxt.y = 90 scoreTxt:setTextColor(255, 255, 255) scoreTxt.alpha = 0.5 group2:insert(scoreTxt) ---:::SCORETEXT for i=1, anzahlLeben do leben[i] = display.newImage("leben1.png") leben[i].anchorX = 0.5 leben[i].anchorY = 0.5 leben[i].x = i\*\_W/10-20 leben[i].y = \_H/22 leben[i].alpha = 0.8 group2:insert(leben[i]) end end function onGameOverTouch(event) if event.phase == "began" then group:removeSelf() group2:removeSelf() -- group = nil display.remove(physics.start()) display.remove(showBG()) display.remove(touched(event)) display.remove(verlauf2(event)) --display.remove(creategegnerZA()) display.remove(killsscore(event)) composer:gotoScene( "menu", "fade", 500 ) end end -- "scene:create()" function scene:create( event ) local group = self.view physics.start() showBG() touched(event) verlauf2(event) creategegnerZA() killsscore() bg:addEventListener("touch", touched) Runtime:addEventListener("collision", onCollision) Runtime:addEventListener("touch", licht) tmr\_creategegnerZA = timer.performWithDelay(gegnerZASpawnSpeed, creategegnerZA, -1) --txt\_gameover2:addEventListener("tap", onGameOverTouch) -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. end -- "scene:show()" function scene:show( event ) local group = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local group = self.view -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

Glad i could help.

a bit more advice - and by no means do you have to follow it -it’s just an observation and only my opinion.

Everyone has their own special way of writing code - whatever way suits them - ( and i am far from an expert - self taught starting with excel macros and VBA).

i found your code hard to follow/read. Part of that might be because of the text wrapping but also related to that is the verylongVariableNames.

But as i said above everybody does things differently.

T.

haha ok thank you, i have a lot to lern and i will work on it. its my first time coding everything, expect of html in school, years ago :smiley:

Might i suggest you rethinking your post above.

If you wish for help you need to help yourself.

On looking at your post ( i guess heavily edited) i would make an educated guess that readers will go what on earth is happening, and get lost in the editing mistakes, thus see this as a very long time intensive fix, and the reality is that time would be better spent on their own projects.

The forum is here to help i.e. you see something which you came across and found a fix so it’s easy to pass on the information that lead to the fix.

As it stands at the moment the code you’ve posted IMHO does not let the forum help you.

I don’t mean to offend just trying to help you get an answer.

T.

im very sorry, i thought i post not the whole code because its quite long and skip the uninteresting things, cause i have not problems with a spec. logic or function or what ever, i have issuse with the removements.

but yes you are right, i could done it better :wink:

ill post the whole code later

On re reading your post - i still think more code was needed (don’t know how big it is).

But shot in the dark here is - are you inserting all display objects into the scene group?

T.

thank you first for spending time

is there a difference between normal groups and sceneGroups? if yes then no i didnt,

but, all displayObject are in a group, called “group” and this group i tryed to remove, but take a look yourself:

the code is a bit unclean,

there the whole code.

menu.lua

display.setStatusBar(display.HiddenStatusBar) local \_H = display.contentHeight; local \_W = display.contentWidth; local centerX = display.contentCenterX local centerY = display.contentCenterY local composer = require( "composer" ) local scene = composer.newScene() local widget = require( "widget" ) local sceneGroup = display.newGroup() -- Touch event listener for background image local function timera() composer.removeScene("endless") -- composer.gotoScene( "factory", "fade", 200 ) return true end local function menue(event) --bg-- bgf = display.newImage("tscreenbg.png") bgf.anchorX = 0.5 bgf.anchorY = 0.5 bgf.x = \_W/2 bgf.y = \_H/2 sceneGroup:insert( bgf ) --buttons-- local function onEndlessRelase() composer:gotoScene( "endless", "fade", 500 ) return true end local function onChaptRelase() composer:gotoScene( "endless", "fade", 500 ) return true end local function onCredbtnRelase() composer:gotoScene( "creds", "fade", 500 ) return true end local endlessbtn = widget.newButton { defaultFile = "endlessbtn.png", label = "endlessbtn", onEvent = onEndlessRelase } endlessbtn.anchorX = 0.5 endlessbtn.anchorY = 0.5 endlessbtn.y = \_H/2 + 50 endlessbtn.x = \_W/2 - 55 sceneGroup:insert(endlessbtn) local chapt = widget.newButton { defaultFile = "chaptbtn.png", label = "chapt", onEvent = onChaptRelase } chapt.anchorX = 0.5 chapt.anchorY = 0.5 chapt.y = \_H/2 + 360 chapt.x = \_W/2 - 5 sceneGroup:insert(chapt) local credbtn = widget.newButton { defaultFile = "creditbtn.png", label = "credbtn", onEvent = onCredbtnRelase } credbtn.anchorX = 0.5 credbtn.anchorY = 0.5 credbtn.y = (\_H/2)/0.5 -50 credbtn.x = \_W/2 sceneGroup:insert(credbtn) end function scene:create( event ) local sceneGroup = self.view end function scene:show( event ) local phase = event.phase if "did" == phase then print( "1: show event, phase did by menue" ) menue(event) local currScene = composer.getSceneName( "previous" ) composer.removeScene( currScene ) -- remove previous scene's view composer.removeScene( "factory" ) -- Update Lua memory text display local showMem = function() end memTimer2 = timer.performWithDelay( 2, timera) end end function scene:hide( event ) local phase = event.phase if "will" == phase then -- cancel timer -- timer.cancel( memTimer2 ); memTimer2 = nil; end end function scene:destroy( event ) print( "destroy menu" ) local removeLastScene = composer.getSceneName( "previous" ) composer.removeScene( removeLastScene ) end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

and endless.lua:

display.setStatusBar(display.HiddenStatusBar) local composer = require( "composer" ) local scene = composer.newScene() local screenW, screenH, halfW, halfH = display.contentWidth, display.contentHeight, display.contentWidth/2, display.contentHeight/2 system.activate("multitouch") \_H = display.contentHeight; \_W = display.contentWidth; local centerX = display.contentCenterX local centerY = display.contentCenterY widget = require( "widget" ) local physics = require "physics" ---:::--- local bg local leftbush local rightbus local topbush local botbush local soldat local lichtkranz local lichtkranz2 local scoreTxt local spawnZeit local leben = {} local steine = {} local gegnerZA = {} local gegnerZAZahl = 1 local score = 0 local kills local bulletSpeed = 2 local anzahlLeben = 3 local anzahlSteine = 5 local gegnerZASpeed = 1500 local gegnerZASpawnSpeed = 1000 local rand = math.random() local radiusMax = math.sqrt( centerX\*centerX + centerY\*centerY ) local group = display.newGroup() -----------------------::::::::::::::::::::::::BGSHOW::::::::::::::::::::::-------------- function onGameOverTouch(event) if event.phase == "began" then composer:gotoScene( "menu", "fade", 500 ) end end local function showBG() bg = display.newImage("bg.png") bg.anchorX = 0.5 bg.anchorY = 0.5 bg.y = \_H/2 bg.x = \_W/2 group:insert(bg) for i=1,anzahlSteine do steine[i] = display.newImageRect("stein.png",100+math.random(50) ,100 + math.random(50),2000,200) steine[i].anchorX = 0.5 steine[i].anchorX = 0.5 --steine[i]:scale(rand, rand) steine[i].x = math.random((\_W-100)) steine[i].y = math.random((\_H-100)) angle = math.deg(math.atan2((centerY-steine[i].y),(centerX-steine[i].x))) steine[i].rotation = angle -90 group:insert(steine[i]) end leftbush = display.newImage("leftbush.png") leftbush.anchorY = 0 leftbush.anchorX = 0 leftbush.y = -200 leftbush.x = -65 group:insert(leftbush) rightbush = display.newImage("rightbush.png") rightbush.anchorY = 0 rightbush.anchorX = 0 rightbush.x = 935 group:insert(rightbush) topbush = display.newImage("topbush.png") topbush.anchorY = 0 topbush.anchorX = 0 topbush.y = -60 group:insert(topbush) botbush = display.newImage("botbush.png") botbush.anchorY = 0 botbush.anchorX = 0 botbush.y = 1795 group:insert(botbush) lichtkranz = display.newImage("lichtkranz.png") lichtkranz.y, lichtkranz.x, lichtkranz.anchorX, lichtkranz.anchorY = \_H/2, \_W/2, 0.5, 0.5 lichtkranz.rotation = -90 lichtkranz.alpha = 1 lichtkranz.blendMode = "add" group:insert(lichtkranz) soldat = display.newImage("soldat.png") soldat.x = \_W/2 soldat.y = \_H/2 soldat.rotation = 0 group:insert(soldat) end ---------------------:::::::::::::BG SHOW::::::::::::::::::::---------- ---------------------:::::::::::::touch:::::::::::::::::::::---------- local function touched(event) if(event.phase == "began" or event.phase == "moved") then --soldatrotation angle = math.deg(math.atan2((event.y-soldat.y),(event.x-soldat.x))) soldat.rotation = angle + 90 --lichtkreis um den soldaten wird rotiert angle = math.deg(math.atan2((event.y-lichtkranz.y),(event.x-lichtkranz.x))) lichtkranz.rotation = angle +90 end if (event.phase == "began") then bullet = display.newImage("bullet.png") bullet.x = halfW+30 bullet.y = halfH -20 physics.addBody( bullet, "dynamic", { isSensor=true, radius=20} ) bullet.name = "bullet" group:insert(bullet) -- Find out if we need to fire the bullet to the left or right local farX = screenW\*2 local slope = ((event.yStart-screenH/2)/(event.xStart-screenW/2)) local yInt = event.yStart - (slope\*event.xStart) if(event.xStart \>= screenW/2)then farX = screenW\*2 else farX = screenW-(screenW\*2) end local farY = (slope\*farX)+yInt local xfactor = farX-bullet.x local yfactor = farY-bullet.y local distance = math.sqrt((xfactor\*xfactor) + (yfactor\*yfactor)) bullet.trans = transition.to(bullet, { time=distance/bulletSpeed, y=farY, x=farX, onComplete=nil}) end end local 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" group: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 + 1 -- 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,32) txt\_gameover.x = halfW txt\_gameover.y = screenH \* 0.3 group: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 = "endlessbtn.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) group:insert(txt\_gameover2) end end; }) gegnerZAZahl = gegnerZAZahl + 1 end 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 == 5) then timer.cancel(tmr\_creategegnerZA) bg:removeEventListener("touch", touched) local spielvorbei = widget.newButton { defaultFile = "endlessbtn.png", label= "endlesssssssssssss", onEvent = onGameOverTouch } spielvorbei.x = \_W/2 spielvorbei.y = \_H/2 spielvorbei.anchorX = 0.5 spielvorbei.anchorY = 0.5 end -- Make the objects invisible event.object1.alpha = 0 event.object2.alpha = 0 -- 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 -------------:::::::::::gegnerZa:::::::::--------- --------------::::::::::verlauf::::::::::-------- local function verlauf2 (event) verlauf = display.newImage("verlauf.png") verlauf.x = \_W/2 verlauf.y = \_H/2 verlauf.anchorX, verlauf.anchorY = 0.5, 0.5 verlauf.alpha = 1 local torch = graphics.newMask("alpha3.png") verlauf:setMask(torch) local lichtkranz2 = display.newImage("lichtkranz.png") lichtkranz2.y, lichtkranz2.x, lichtkranz2.anchorX, lichtkranz2.anchorY = \_H/2, \_W/2, 0.5, 0.5 lichtkranz2.blendMode = "add" lichtkranz2.alpha = 0.3 lichtkranz2.isVisible = false local radiusMax = math.sqrt( centerX\*centerX + centerY\*centerY ) function licht (event) verlauf.maskY = event.y -\_H/2 verlauf.maskX = event.x - \_W/2 lichtkranz2.x = event.x lichtkranz2.y = event.y lichtkranz2.Xscale = 0.2 lichtkranz2.isVisible = true --::torcheffect 4 Mask::-- -- Stretch the flashlight as it moves further away -- from the screen's center local radius = math.sqrt( verlauf.maskX\*verlauf.maskX + verlauf.maskY\*verlauf.maskY ) local scaleDelta = radius/radiusMax verlauf.maskScaleX = 1.3 + scaleDelta verlauf.maskScaleY = 1 + 0.2 \* scaleDelta -- Rotate it appropriately about screen center local rotation = math.deg( math.atan2( verlauf.maskY, verlauf.maskX ) ) verlauf.maskRotation = rotation --::torcheffekt4 Mask::-- --::torcheffect4 lichtkranz2::--local radius = math.sqrt( verlauf.maskX\*verlauf.maskX + verlauf.maskY\*verlauf.maskY ) local scaleDelta = radius/radiusMax lichtkranz2.ScaleX = 1 + scaleDelta lichtkranz2.ScaleY = 1 + 0.2 \* scaleDelta -- Rotate it appropriately about screen center local rotation = math.deg( math.atan2( lichtkranz2.y, lichtkranz2.x ) ) lichtkranz2.rotation = rotation -- bg:addEventListener("touch", licht) end end local function killsscore() kills = display.newImage("kills.png") kills.anchorX = 0.5 kills.anchorY = 0.5 kills.x = \_W/2 - 30 kills.y = \_H/25 -- group:insert(kills) scoreTxt = display.newText(""..score,0,0,PWChalk,80) scoreTxt.x = \_W/2 +250 scoreTxt.y = 90 scoreTxt:setTextColor(255, 255, 255) scoreTxt.alpha = 0.5 --group:insert(scoreTxt) ---:::SCORETEXT for i=1, anzahlLeben do leben[i] = display.newImage("leben1.png") leben[i].anchorX = 0.5 leben[i].anchorY = 0.5 leben[i].x = i\*\_W/10-20 leben[i].y = \_H/22 leben[i].alpha = 0.8 --group:insert(leben[i]) end end -- "scene:create()" function scene:create( event ) local group = self.view physics.start() showBG() touched(event) verlauf2(event) creategegnerZA() killsscore() bg:addEventListener("touch", touched) Runtime:addEventListener("collision", onCollision) Runtime:addEventListener("touch", licht) tmr\_creategegnerZA = timer.performWithDelay(gegnerZASpawnSpeed, creategegnerZA, -1) --txt\_gameover2:addEventListener("tap", onGameOverTouch) -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. end -- "scene:show()" function scene:show( event ) local group = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then physics.stop() bg:removeEventListener("touch", touched) Runtime:removeEventListener("collision", onCollision) Runtime:removeEventListener("touch", licht) -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local group = self.view group:removeSelf() group = nil display.remove(showBG()) display.remove(touched(event)) display.remove(verlauf2(event)) display.remove(creategegnerZA()) display.remove(killsscore()) --local currScene = composer.getSceneName( "current" ) --composer.removeScene( currScene ) print("remove zeusch") -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

tank you 

Yes i think your problem is with groups.

1st thing to do is download a fresh copy of the composer template untouched. Use this to compare your composer codes against the std composer code - to my knowledge composer always uses sceneGroup - you have changed a few to group. BUT don’t get confused with the group that you set up -two different things.

composer group is the base - if you don’t insert things in here when you leave a scene things will remain.

But you can also set up sub groups to help with layout design.

    local group = display.newGroup()

is the code to set up sub groups

local sceneGroup = self.view

is the composer group thing

So i think getting an understanding of this will help you on your way - check out the composer tuts as well.

T.

i did it, oh my god, 3 whole free days and now i did it, im so unbelivable happy :slight_smile:

thank you my friend you helped me a lot :wub:

you was right, and not too.

first, i put all the remove calls into the onGameOverTouch function.

after that i had an error, the code:

group:removeSelf()

and

group = nil

is not compartible.

quick fix and lock there, it changes (after removing the composer.removeHidden() function from menu.lua)

i put the objects verlauf, score, leben and lichtkranz2 in a seperat group (because in the normal group, it would gives me some layout problems)

took the group2 into the onGameOverTouch function, set it to remove it self and TADA :wub:

if your interested, there is the code:

display.setStatusBar(display.HiddenStatusBar) local composer = require( "composer" ) local scene = composer.newScene() local screenW, screenH, halfW, halfH = display.contentWidth, display.contentHeight, display.contentWidth/2, display.contentHeight/2 system.activate("multitouch") \_H = display.contentHeight; \_W = display.contentWidth; local centerX = display.contentCenterX local centerY = display.contentCenterY widget = require( "widget" ) local physics = require "physics" ---:::--- local bg local leftbush local rightbus local topbush local botbush local soldat local lichtkranz local lichtkranz2 local scoreTxt local spawnZeit local leben = {} local steine = {} local gegnerZA = {} local gegnerZAZahl = 1 local score = 0 local kills local bulletSpeed = 2 local anzahlLeben = 3 local anzahlSteine = 5 local gegnerZASpeed = 1500 local gegnerZASpawnSpeed = 1000 local rand = math.random() local radiusMax = math.sqrt( centerX\*centerX + centerY\*centerY ) -----------------------::::::::::::::::::::::::BGSHOW::::::::::::::::::::::-------------- local group = display.newGroup() local group2 = display.newGroup() local function showBG() bg = display.newImage("bg.png") bg.anchorX = 0.5 bg.anchorY = 0.5 bg.y = \_H/2 bg.x = \_W/2 group:insert(bg) for i=1,anzahlSteine do steine[i] = display.newImageRect("stein.png",100+math.random(50) ,100 + math.random(50),2000,200) steine[i].anchorX = 0.5 steine[i].anchorX = 0.5 --steine[i]:scale(rand, rand) steine[i].x = math.random((\_W-100)) steine[i].y = math.random((\_H-100)) angle = math.deg(math.atan2((centerY-steine[i].y),(centerX-steine[i].x))) steine[i].rotation = angle -90 group:insert(steine[i]) end leftbush = display.newImage("leftbush.png") leftbush.anchorY = 0 leftbush.anchorX = 0 leftbush.y = -200 leftbush.x = -65 group:insert(leftbush) rightbush = display.newImage("rightbush.png") rightbush.anchorY = 0 rightbush.anchorX = 0 rightbush.x = 935 group:insert(rightbush) topbush = display.newImage("topbush.png") topbush.anchorY = 0 topbush.anchorX = 0 topbush.y = -60 group:insert(topbush) botbush = display.newImage("botbush.png") botbush.anchorY = 0 botbush.anchorX = 0 botbush.y = 1795 group:insert(botbush) lichtkranz = display.newImage("lichtkranz.png") lichtkranz.y, lichtkranz.x, lichtkranz.anchorX, lichtkranz.anchorY = \_H/2, \_W/2, 0.5, 0.5 lichtkranz.rotation = -90 lichtkranz.alpha = 1 lichtkranz.blendMode = "add" group:insert(lichtkranz) soldat = display.newImage("soldat.png") soldat.x = \_W/2 soldat.y = \_H/2 soldat.rotation = 0 group:insert(soldat) end ---------------------:::::::::::::BG SHOW::::::::::::::::::::---------- ---------------------:::::::::::::touch:::::::::::::::::::::---------- local function touched(event) if(event.phase == "began" or event.phase == "moved") then --soldatrotation angle = math.deg(math.atan2((event.y-soldat.y),(event.x-soldat.x))) soldat.rotation = angle + 90 --lichtkreis um den soldaten wird rotiert angle = math.deg(math.atan2((event.y-lichtkranz.y),(event.x-lichtkranz.x))) lichtkranz.rotation = angle +90 end if (event.phase == "began") then bullet = display.newImage("bullet.png") bullet.x = halfW+30 bullet.y = halfH -20 physics.addBody( bullet, "dynamic", { isSensor=true, radius=20} ) bullet.name = "bullet" group:insert(bullet) -- Find out if we need to fire the bullet to the left or right local farX = screenW\*2 local slope = ((event.yStart-screenH/2)/(event.xStart-screenW/2)) local yInt = event.yStart - (slope\*event.xStart) if(event.xStart \>= screenW/2)then farX = screenW\*2 else farX = screenW-(screenW\*2) end local farY = (slope\*farX)+yInt local xfactor = farX-bullet.x local yfactor = farY-bullet.y local distance = math.sqrt((xfactor\*xfactor) + (yfactor\*yfactor)) bullet.trans = transition.to(bullet, { time=distance/bulletSpeed, y=farY, x=farX, onComplete=nil}) end end local 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" group: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 + 1 -- 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,32) txt\_gameover.x = halfW txt\_gameover.y = screenH \* 0.3 group: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 = "endlessbtn.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) group:insert(txt\_gameover2) end end; }) gegnerZAZahl = gegnerZAZahl + 1 end 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 = "endlessbtn.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 -- 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 -------------:::::::::::gegnerZa:::::::::--------- --------------::::::::::verlauf::::::::::-------- local function verlauf2 (event) verlauf = display.newImage("verlauf.png") verlauf.x = \_W/2 verlauf.y = \_H/2 verlauf.anchorX, verlauf.anchorY = 0.5, 0.5 verlauf.alpha = 1 local torch = graphics.newMask("alpha3.png") verlauf:setMask(torch) local lichtkranz2 = display.newImage("lichtkranz.png") lichtkranz2.y, lichtkranz2.x, lichtkranz2.anchorX, lichtkranz2.anchorY = \_H/2, \_W/2, 0.5, 0.5 lichtkranz2.blendMode = "add" lichtkranz2.alpha = 0.5 lichtkranz2.isVisible = false group2:insert(lichtkranz2) group2:insert(lichtkranz) group2:insert(verlauf) group2:insert(soldat) local radiusMax = math.sqrt( centerX\*centerX + centerY\*centerY ) function licht (event) verlauf.maskY = event.y -\_H/2 verlauf.maskX = event.x - \_W/2 lichtkranz2.x = event.x lichtkranz2.y = event.y lichtkranz2.Xscale = 0.2 lichtkranz2.isVisible = true --::torcheffect 4 Mask::-- -- Stretch the flashlight as it moves further away -- from the screen's center local radius = math.sqrt( verlauf.maskX\*verlauf.maskX + verlauf.maskY\*verlauf.maskY ) local scaleDelta = radius/radiusMax verlauf.maskScaleX = 1.3 + scaleDelta verlauf.maskScaleY = 1 + 0.2 \* scaleDelta -- Rotate it appropriately about screen center local rotation = math.deg( math.atan2( verlauf.maskY, verlauf.maskX ) ) verlauf.maskRotation = rotation --::torcheffekt4 Mask::-- --::torcheffect4 lichtkranz2::--local radius = math.sqrt( verlauf.maskX\*verlauf.maskX + verlauf.maskY\*verlauf.maskY ) local scaleDelta = radius/radiusMax lichtkranz2.ScaleX = 1 + scaleDelta lichtkranz2.ScaleY = 1 + 0.2 \* scaleDelta -- Rotate it appropriately about screen center local rotation = math.deg( math.atan2( lichtkranz2.y, lichtkranz2.x ) ) lichtkranz2.rotation = rotation -- bg:addEventListener("touch", licht) end end local function killsscore() kills = display.newImage("kills.png") kills.anchorX = 0.5 kills.anchorY = 0.5 kills.x = \_W/2 - 30 kills.y = \_H/25 group2:insert(kills) scoreTxt = display.newText(""..score,0,0,PWChalk,80) scoreTxt.x = \_W/2 +250 scoreTxt.y = 90 scoreTxt:setTextColor(255, 255, 255) scoreTxt.alpha = 0.5 group2:insert(scoreTxt) ---:::SCORETEXT for i=1, anzahlLeben do leben[i] = display.newImage("leben1.png") leben[i].anchorX = 0.5 leben[i].anchorY = 0.5 leben[i].x = i\*\_W/10-20 leben[i].y = \_H/22 leben[i].alpha = 0.8 group2:insert(leben[i]) end end function onGameOverTouch(event) if event.phase == "began" then group:removeSelf() group2:removeSelf() -- group = nil display.remove(physics.start()) display.remove(showBG()) display.remove(touched(event)) display.remove(verlauf2(event)) --display.remove(creategegnerZA()) display.remove(killsscore(event)) composer:gotoScene( "menu", "fade", 500 ) end end -- "scene:create()" function scene:create( event ) local group = self.view physics.start() showBG() touched(event) verlauf2(event) creategegnerZA() killsscore() bg:addEventListener("touch", touched) Runtime:addEventListener("collision", onCollision) Runtime:addEventListener("touch", licht) tmr\_creategegnerZA = timer.performWithDelay(gegnerZASpawnSpeed, creategegnerZA, -1) --txt\_gameover2:addEventListener("tap", onGameOverTouch) -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. end -- "scene:show()" function scene:show( event ) local group = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local group = self.view -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

Glad i could help.

a bit more advice - and by no means do you have to follow it -it’s just an observation and only my opinion.

Everyone has their own special way of writing code - whatever way suits them - ( and i am far from an expert - self taught starting with excel macros and VBA).

i found your code hard to follow/read. Part of that might be because of the text wrapping but also related to that is the verylongVariableNames.

But as i said above everybody does things differently.

T.

haha ok thank you, i have a lot to lern and i will work on it. its my first time coding everything, expect of html in school, years ago :smiley: