Hello everyone, Okay I got a lot of code working with a lot of all you help !! thanks…
In my levelOne scene I have sprites moving down the screen and when the go off screen I want to be a good newBee and clean up my mess, but the code does not seem to be working, Actually the code only removes the last sprite off the screen to be removed.
How do I know , well I set the bottom of the screen to be +10 so I can still see if they were cleaned up.
So what do i do?
Here is my code.
function scene:create( event )
local sceneGroup = self.view
local phase = event.phase
function timerFunction( )
tmr = timer.cancel()
end
function addEnemy( event )
sheetData = {
width = 170,
height = 160,
numFrames = 10,
sheetContentWidth = 850,
sheetContentHeight = 320 }
mySheet = graphics.newImageSheet(“spritesheet.png”,sheetData)
sequenceData = {
{ name = “normalRun”,start=1,count=10,time=2200},
{name = “fastRun”,frames = {1,2,3,4,5,6,7,8,9,10},time = animationTime}
}
animation = display.newSprite(mySheet,sequenceData)
animation.x = math.random(20,300)
animation.y = 160
animation.xScale = .4
animation.yScale = .3
--physics.addBody (animation,“static”,{density= 10,friction= 0,bounce=0}) --,radius=25}) or shape =
animation:setSequence(“fastRun”)
animation:play()
sceneGroup:insert(animation)
randomY = (display.contentHeight +10)
transition.to (animation, {x = animation.x, y = randomY, time = downWardSpeed})
enemieCount = enemieCount + 1
local function removeEnemy( event )
print (“I made it to removeEnemy”)
animation:removeSelf()
animation = nil
end
if enemieCount < enemiesOnStage then
tmr = timer.performWithDelay(1000,addEnemy)
elseif enemieCount == enemiesOnStage then
timer.performWithDelay (4000,removeEnemy)
timer.cancel(tmr)
end
end
addEnemy()
end