hey guys
i have an object spawning every 2.9 seconds
but the problem is that it spawns over other display objects
i tried every possibilities that i could but all in vein
Code :
local composer = require( "composer" ) local widget = require "widget" local scene = composer.newScene() -- ----------------------------------------------------------------------------------- -- Code outside of the scene event functions below will only be executed ONCE unless -- the scene is removed entirely (not recycled) via "composer.removeScene()" -- ----------------------------------------------------------------------------------- local trans\_virus, timer\_virus local button1, button2, button3 local moneybar, keybar, key, moneyText, keyText local backgroundTitle local virus -- ----------------------------------------------------------------------------------- -- Scene event functions -- ----------------------------------------------------------------------------------- local function spawnVirus() virus = display.newImageRect("menuImages/virus.png",100,100) virus.x = math.random(screenLeft + screenWidth \* 0.1, screenRight - screenWidth \* 0.1) virus.y = screenTop - virus.height trans\_virus = transition.to(virus, { y = screenBottom + virus.height , time =3000, onComplete = function (self) display.remove(self); self = nil; print("removed") end }) backgroundTitle:toFront() button1:toFront() button2:toFront() button3:toFront() moneybar:toFront() moneyText:toFront() keybar:toFront() keyText:toFront() key:toFront() end local function onButtonTouch( event ) -- body if (event.phase == "ended") then composer.gotoScene("scene\_"..event.target.name,"crossFade") if virus~= nil then display.remove(virus) virus = nil end if timer\_virus then timer.cancel(timer\_virus) end end end -- create() function scene:create( event ) local sceneGroup = self.view -- Code here runs when the scene is first created but has not yet appeared on screen -- background, music local backgroundImage = display.newImageRect(sceneGroup,"menuImages/image\_background.png",640,1200) backgroundImage.x = centerX backgroundImage.y = centerY backgroundImage.width = screenWidth backgroundImage.height = screenHeight backgroundTitle = display.newText ("Ball Saver",0,0,\_titleFont,200) backgroundTitle.x = centerX backgroundTitle.y = screenHeight \* 0.2 if user.playSound == true then audio.setVolume(1) else audio.setVolume(0) end --buttons button1 = widget.newButton { width = 400 , height = 100 , defaultFile = "menuImages/button1.png", overFile = "menuImages/button1\_over.png", font = \_font, fontSize = 55 , label = "Play", labelColor = { default = {1,1,1} , over = {1,0.9,1} }, onEvent = onButtonTouch } button1.x = centerX button1.y = centerY button1.name = "play" button2 = widget.newButton { width = 400 , height = 100 , defaultFile = "menuImages/button2.png", overFile = "menuImages/button2\_over.png", font = \_font, fontSize = 55 , label = "Upgrades", labelColor = { default = {1,1,1} , over = {1,0.9,1} }, onEvent = onButtonTouch } button2.x = centerX button2.y = button1.y + button1.width \* 0.35 button2.name = "upgrades" button3 = widget.newButton { width = 400 , height = 100 , defaultFile = "menuImages/button3.png", overFile = "menuImages/button3\_over.png", font = \_font, fontSize = 55 , label = "Options", labelColor = { default = {1,1,1} , over = {1,0.9,1} }, onEvent = onButtonTouch } button3.x = centerX button3.y = button2.y + button2.width \* 0.35 button3.name = "options" -- money moneybar = display.newImageRect(sceneGroup,"menuImages/bar.png",140,50) moneybar.anchorX = 1 moneybar.x = screenRight - 25 moneybar.y = screenTop + moneybar.height moneyText = display.newText(sceneGroup, "$".." "..user.money,0,0,\_font,30) moneyText.anchorX = 1 moneyText.x = moneybar.x - moneybar.width \* 0.1 moneyText.y = moneybar.y -- keys keybar = display.newImageRect(sceneGroup,"menuImages/bar.png",140,50) keybar.anchorX = 1 keybar.anchorY = 0 keybar.x = screenRight - 25 keybar.y = screenTop + keybar.height \* 2 key = display.newImageRect (sceneGroup,"menuImages/ruby.png",40,60) key.anchorX = 0 key.anchorY = 0 key.x = keybar.x - keybar.width \* 0.9 key.y = keybar.y - key.height \* 0.1 keyText = display.newText(sceneGroup, ""..user.keys,0,0,\_font,30) keyText.x = key.x + keybar.width \* 0.5 keyText.y = key.y + key.width \* 0.8 if user.money \> 9999 then moneybar.xScale = 1.1 moneyText.anchorX = 1 moneyText.x = moneybar.x - moneybar.width \* 0.15 end if user.money \> 99999 then moneybar.xScale = 1.3 moneyText.anchorX = 1 moneyText.x = moneybar.x - moneybar.width \* 0.2 end --inserting into sceneGroup sceneGroup:insert(button1) sceneGroup:insert(button2) sceneGroup:insert(button3) sceneGroup:insert(backgroundTitle) print(display.imageSuffix) end -- show() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen --viruses timer\_virus = timer.performWithDelay(2900,spawnVirus,0) end end -- hide() function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) timer.cancel(timer\_virus) elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene
local function spawnVirus spawns my object… i wanted all other objects to place over it