Whatsup community
Ive been playing around trying to imitate a background i saw (but turn it into a simple game). Then i came across a problem where i couldnt remove the fallings objects through a table. Hmmmmmm
display.setStatusBar( display.HiddenStatusBar ) ----------------------------------------------------------------------------------------- -- Localize to improve performance ----------------------------------------------------------------------------------------- local W = display.contentWidth local H = display.contentHeight local XCentre = display.contentCenterX local YCentre = display.contentCenterY local screenLeft = display.screenOriginX local screenRight = display.viewableContentWidth + display.screenOriginX local screenTop = display.screenOriginY local screenBottom = display.viewableContentHeight + display.screenOriginY ---------------------------------------------------------------------------------------- -- Start and manipulate physics to suit environment/ game style ---------------------------------------------------------------------------------------- local physics = require("physics") local heroSpeed = 200 local random = math.random physics.start() physics.setGravity( 0, 0 ) ---------------------------------------------------------------------------------------- -- Add a bit of colour because things were looking boring ! ---------------------------------------------------------------------------------------- local BG = display.setDefault( "background", 0,1,1 ) ---------------------------------------------------------------------------------------- -- create table to hold our badguys! ---------------------------------------------------------------------------------------- local BG = {} local BadGuyNumb = 0 ---------------------------------------------------------------------------------------- -- Display, add Physics and insert BadGuys into a table ---------------------------------------------------------------------------------------- local function SpawnBadGuys () local Size = random (20,90) local BadGuy = display.newRect(random(screenLeft,screenRight), 0, Size, Size ) table.insert( BG, BadGuy) physics.addBody( BadGuy) BadGuy.isSensor = true transition.to( BadGuy,{time = random (1000,3000), y = screenBottom --[[+ Size \* .5]], onComplete = Destroy\_BadGuy} ) return BadGuy end local function Destroy\_BadGuy () BadGuyNumb = BadGuyNumb + 1 display.remove( BG[BadGuyNumb] ) BG[BadGuyNumb] = nil end timer.performWithDelay( random (120,500), SpawnBadGuys , -1)
Thanks a bunch (and hello from england!)