I’m creating a space shooter game where the enemy ships will appear in two rows of 8 at the top of the screen in Level 1.
I created a For Loop to handle the multiple enemy ships which is handled in a table. I don’t have a problem with the first row and everything displays fine. When creating the second row I’m having a problem coming up with the code to display it correctly. Here’s the code:
local function loadEnemies()
for i = 1, 10 do
enemyTable[numOfEnemies] = display.newImage(“enemy1.png”)
enemyTable[numOfEnemies]:scale(.4,.4)
enemyTable[numOfEnemies]:setReferencePoint(display.CenterLeftReferencePoint)
enemyTable[numOfEnemies].x = (numOfEnemies * (display.viewableContentWidth * .025))
enemyTable[numOfEnemies].myName=“enemy”
numOfEnemies= numOfEnemies + 5
end
end
The top row displays fine. I have 8 enemy ships appearing at the top based on the code above. I increment the numOfEnemies by 5 each pass to be able to create space between the ships. My question is,“How would I create another row of enemy fighters so that I have a total of 16 on the screen to start the game?” So in essence, “How could I change the y position and possibly refer back to the previous 8 ship’s x position so that they are perfectly aligned?” Also, I created the enemyTable and numOfEnemies variables as local variables outside of the function.
Thanks in advance. Corona is an amazing tool!
[import]uid: 115755 topic_id: 22151 reply_id: 322151[/import]