Hi, guys. I need a help. That’s a summary of my code and I have performance problems when gameloop spawns some enemies. I think could be timer.performWithDelay that I use for each enemy movement. Am I right? Is there another way to create enemy and move it? Thanks.
local lastEnemy = 0
function createEnemy_1()
local enemy
function moveEnemy(event)
enemy.y = enemy.y + gameMoveSpeed
if enemy.y > display.contentHeight + enemy.height*.5 then
timer.cancel(event.source)
enemy:removeSelf()
end
end
timer.performWithDelay(1, moveEnemy, 0)
end
function createEnemy_2()
local enemy
function moveEnemy(event)
enemy.y = enemy.y + gameMoveSpeed
if enemy.y > display.contentHeight + enemy.height*.5 then
timer.cancel(event.source)
enemy:removeSelf()
end
end
timer.performWithDelay(1, moveEnemy, 0)
end
.
.
.
function createEnemy_n()
local enemy
function moveEnemy(event)
enemy.y = enemy.y + gameMoveSpeed
if enemy.y > display.contentHeight + enemy.height*.5 then
timer.cancel(event.source)
enemy:removeSelf()
end
end
timer.performWithDelay(1, moveEnemy, 0)
end
function spawnEnemies(params)
local e = params.e
if e==1 then createEnemy_1()
if e==2 then createEnemy_2()
.
.
.
if e==n then createEnemy_n()
end
function gameLoop(event) –EnterFrame
if event.time - lastEnemy >= math.random(500, 3000) then
spawnEnemies({e=math.random(1,n)})
lastEnemy = event.time
end
.
.
.
end
[import]uid: 40281 topic_id: 13009 reply_id: 313009[/import]
[import]uid: 52491 topic_id: 13009 reply_id: 47844[/import]