Infinite loop for game

Hey Guys and ladies

I need some help on my project. what i’m trying to do is to spawn the enemy’s for ever/infinite and as you progress through the game, more and more enemy’s are spawned . At the moment its only spawning one enemy. I would really appreciate it if you modify my code  and then just post it back on this topic so i can get an idea of what i’m doing wrong and what i can put in my project

Here is my code.

function spawnEnemy() local enemyBalloon = display.newImage(Balloons,”Balloon.png”) physics.addBody(enemyBalloon,”dynamic”, physicsData:get(“balloon”) ) if math.random(2) == 1 then enemyBalloon.x = math.random(-100,-10) else enemyBalloon.x = math.random(display.contentWidth+10,display.contentWidth +100) end enemyBalloon.x = math.random(display.contentWidth) enemyBalloon.y = -60 end spawnEnemy()  

cheers, Hazza

its because you are only calling the spawnEnemy function once

you can use a timer to keep calling the function

so replace the line spawnEnemy() with the following

local spawnTimer = timer.performWithDelay( 2000, spawnEnemy, 0 ) -- fires every 2 seconds

thank you so much, helped a lot, i’m still learning and its quiet  a bit for me to take in.

how would I make it so that for every 15 seconds twice the amount of enemy’s are spawned?

I would do something like this

local enemyNumber = 1 -- starting number of enemies local function spawnEnemy() -- Need to add your enemy code in here, will need a 'for loop' to place each of them print(enemyNumber) -- shows you how many enemies will be on screen end local function increaseEnemy() enemyNumber = enemyNumber \* 2 -- doubles the current amount of enemies spawnEnemy() end local spawnTimer = timer.performWithDelay( 15000, increaseEnemy, 0 ) -- fires every 15 seconds

its because you are only calling the spawnEnemy function once

you can use a timer to keep calling the function

so replace the line spawnEnemy() with the following

local spawnTimer = timer.performWithDelay( 2000, spawnEnemy, 0 ) -- fires every 2 seconds

thank you so much, helped a lot, i’m still learning and its quiet  a bit for me to take in.

how would I make it so that for every 15 seconds twice the amount of enemy’s are spawned?

I would do something like this

local enemyNumber = 1 -- starting number of enemies local function spawnEnemy() -- Need to add your enemy code in here, will need a 'for loop' to place each of them print(enemyNumber) -- shows you how many enemies will be on screen end local function increaseEnemy() enemyNumber = enemyNumber \* 2 -- doubles the current amount of enemies spawnEnemy() end local spawnTimer = timer.performWithDelay( 15000, increaseEnemy, 0 ) -- fires every 15 seconds