Hello,
I need to dynamically generate display groups. It should be pretty easy but I’m getting stuck. Here’s my code so far:
[lua]local currentX = 50;
local monsterCounter = 0;
local function spawnMonster()
local monster = display.newRect(50,50,50,50);
monsterCounter = monsterCounter + 1;
_G[“monsterDisplayGroup”…monsterCounter] = display.newGroup();
_G[“monsterDisplayGroup”…monsterCounter]:insert(monster);
transition.to(_G[“monsterDisplayGroup”…monsterCounter], {x=300, time=2000, onComplete = function()
_G[“monsterDisplayGroup”…monsterCounter]:removeSelf();
print("removing: ");
print(_G[“monsterDisplayGroup”…monsterCounter]);
end});
end
timer.performWithDelay(2000, spawnMonster, 5);[/lua]
Also, I have read it’s not a good idea to use _G like this - so what is a better alternative?
Thanks!
Tom [import]uid: 55068 topic_id: 14166 reply_id: 314166[/import]