lua - How can I remove all spawned objects from the screen? -


i'm trying make simple dodging game includes pickup falls top of screen: "wplaser"

when player touches pickup, want of spawned projectiles ("default") on screen removed (is possible?)

the issue want projectiles continue spawning after pickup has been picked-up

here of code reference:

local composer = require("composer") local widget = require("widget") local scene = composer.newscene()  local physics = require( "physics" ) -- using physics collision detections physics.start() physics.setgravity( 0, 0 )  -- object group removal local objectgroup = display.newgroup()  -- set variables _w = display.contentwidth; -- width of screen _h = display.contentheight; -- height of screen  function scene:create( event )     local scenegroup = self.view 

here projectiles want removed when player touches pickup:

-- projectiles     local numberdefault = 1 --local variable; amount can changed      local function cleardefault( thisdefault )         display.remove( thisdefault ) ; thisdefault = nil     end      local function spawndefault()         i=1,numberdefault             local default = display.newimage( "projectiles/default.png" )             default.x = math.random( 0, _w )             default.y = -100             default.myname = "default"             default.class = "default"              physics.addbody( default, "dynamic", { density = 0, friction = 0, bounce = 0, issensor = true, radius = 30 } )             transition.to( default, { x = math.random( 0, _w ), y = 1200, time = 4000, oncomplete = cleardefault } )              objectgroup:insert( default )         end     end      timerdefault = timer.performwithdelay( 250, spawndefault, 0 )  -- spawn 1 every 250 units 

and pickup itself:

-- laser power-up     local numberwplaser = 1 --local variable; amount can changed      local function clearwplaser( thiswplaser )         display.remove( thiswplaser ) ; thiswplaser = nil     end      local function spawnwplaser()         i=1,numberwplaser             local wplaser = display.newimage( "images/wplaser.png" )             wplaser.x = math.random( 0, _w )             wplaser.y = -100             wplaser.myname = "wplaser"              physics.addbody( wplaser, "dynamic", { density = 0, friction = 0, bounce = 0, issensor = true, radius = 40 } )             transition.to( wplaser, { x = wplaser.x, y = 1200, time = 5000, oncomplete = clearwplaser } )              objectgroup:insert( wplaser )          end     end      timerwplaser = timer.performwithdelay( 5000, spawnwplaser, 0 )  -- spawn 1 every 5000 units  -- collision detection events     local function oncollision( event )         if event.phase == "began" -- event called when begins (not when ends)             if ( event.object1.myname == "player" , event.object2.myname == "default")                 print( "you died" ) 

this having difficulty. when player touches pickup, want of spawned objects on screen removed continue spawned. currently, projectiles being removed, can't them start spawning again.

            elseif ( event.object1.myname == "player" , event.object2.myname == "wplaser")                 event.object2:removeself()                 transition.cancel( default )                  timer.pause( timerdefault )                 timer.pause( timerwplaser )                  local pickupsound = audio.loadsound( "audio/pickup.mp3" )                 local pickupchannel = audio.play( pickupsound )                  local blank = display.newrect( _w/2, _h/2, _w, _h )                 blank.myname = "blank"                 transition.to( blank, { time = 800, alpha = 0, oncomplete = clearblank } )                  objectgroup:removeself( )                 objectgroup = nil                  print( "pickup" )             end         end     end  runtime:addeventlistener( "collision", oncollision ) end 

sorry dumping of code here, if need confirmation please ask. assistance appreciated

every "250 units" spawndefault adds objects objectgroup. in handler "player touches pickup", set objectgroup nil. tell me, spawndefault going add objects next time runs?


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -