hii…i way trying to understand spawning and pooling concept so i worte a simple program
there is an error after first iteration…
:- attempt to call method ‘removeSelf’(a nil value)
what i am trying to do
:- create two objetcs and put them in a table (t)
:-create a variable and assign a random value from the object in it
:-make the variable visible
:-after it crosses the screen …make the variable empty and again put a random value in it and so on
here is my code
local physics=require("physics") physics.start() local enemy local t={} local ball=display.newCircle(0,0,20) ball:setFillColor(1) ball.isVisible=false table.insert(t,ball) local ball1=display.newCircle(0,0,20) ball1:setFillColor(0.25,0.25,0.60) table.insert(t,ball1) ball1.isVisible=false print(#t) local function update() enemysel() end function enemysel() if(enemy==nil)then enemy=t[math.random(#t)] enemy.isVisible=true enemy.x=300+display.screenOriginX enemy.y=400+display.screenOriginY end if(enemy~=nil)then if(enemy.x\>100)then enemy.x=enemy.x-3 else enemy:removeSelf() enemy=nil end end end timer.performWithDelay(1,update,-1);