Sorry I know this is really basic/lame but it is holding me back. I’m using a function to iterate through a table and spawn a new enemy.
[lua]local enemyTable ={}
loadShip = function()
smallShip1 = {}
smallShip1.image = “shipSmall.png”
smallShip1.x = 1500
smallShip1.y = 172
smallShip1.s = 0.3 – Speed
smallShip1.d = “left” – Direction
smallShip1.h = 200 – Health
smallShip1.myName = “smallShip1”
table.insert(enemyTable, smallShip1)
end
spawnEnemies = function()
enemyProp = enemyTable[math.random(1, #enemyTable)]
enemy = display.newImage(enemyProp.image)
enemy.x = enemyProp.x
enemy.y = enemyProp.y
enemy.myName = enemyProp.myName
enemy.s = enemyProp.s
enemy.d = enemyProp.d
enemy.h = enemyProp.h
enemy:setReferencePoint( display.CenterReferencePoint )
physics.addBody( enemy, “static”, { isSensor = true, shape = smallShipShape } )
enemyGroup:insert(enemy)
enemyShipCount = enemyShipCount + 1;
return enemy
end
loadEnemyShips = function()
if enemyShipCount <= 1 then
spawnEnemies()
end
end[/lua]
When the enemy is spawned I use a basic enterFrame listener to move the enemy around and control it’s particles and a few other little things. For example
[lua]enemy.x = enemy.x - enemy.s [/lua]
My problem is when I spawn more enemies the properties move over to the new “enemy” and the old ones stop moving. What are they now called inside the script? I know this is all tied up in the name “enemy” but I can’t wrap my brain around how to fix it.
Any suggestions?
Thanks heaps [import]uid: 26289 topic_id: 15011 reply_id: 315011[/import]
