Hi guys,
Please help me with this :blink:
I am spawning players and enemies in the same function (do not ask why
).
local playersGroup = display.newGroup() local enemyGroup = display.newGroup() local numOfPlayersCreated = 0 local function spawn() numOfPlayersCreated = numOfPlayersCreated + 1 local player = display.newImageRect(playersGroup, "images/player.png", 50, 50) player. x = 50 player.y = 100 player.id = numOfPlayersCreated local enemy = display.newImageRect(enemyGroup, "images/enemy.png", 50, 50) enemy.x = 300 enemy.y = 200 enemy.id = player.id end
Later on each enemy attacks its own player by selecting precise group index:
self.id = index playersGroup[index]... enemyGroup[index]...
Problem is as I display.remove(enemyGroup[index]) things/group indexes mix up…
Do you have better solution how to tie together enemys and players that are spawned together (only those spawned together)?
Many thanks!
Ivan
