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