Hi Everyone,
I have recently started with Lua and i have searched through many web pages about spawning objects but i don’t think i have it quite right.
I have a storyboard setup and into my main group i am putting about 7 other display groups to create layers in my scene.
On one of these layers i want to spawn clouds to float across the sky.
I got this working in a basic example, but now i am trying to do it in a more complex set up it is not working.
local function makeCloud()
print ("make cloud called, count " .. cloudInstanceCount)
if(cloudsGrp.numChildren) then
print ("cloud group num children # " .. cloudsGrp.numChildren)
else
print ("no children in the group")
end
local imgpath = "Cloud.png";
local imgw = math.random( 50, 200 )
local imgh = (imgw / 100 ) \* 59
local movementSpeed = 32000;
cloudInstanceTable[cloudInstanceCount] = display.newImageRect(imgDir..imgpath, imgw, imgh )
cloudInstanceTable[cloudInstanceCount].y = math.random(59,(display.contentHeight/3))
cloudInstanceTable[cloudInstanceCount].x = display.contentWidth
cloudInstanceTable[cloudInstanceCount].myName = "cloud" .. #cloudInstanceTable + 1
cloudsGrp:insert(cloudInstanceTable[cloudInstanceCount]);
cloudInstanceTable[cloudInstanceCount].transition\_id = transition.to(cloudsGrp, {
time=movementSpeed,
x=-display.contentWidth,
onComplete = function(self)cloudsGrp:remove(self); self = nil; end
}) -- Move the cloud
cloudInstanceCount = cloudInstanceCount + 1
end -- end makeCloud()
local function startClouds(day)
print ("start clouds called")
if day == "day" then
cloudTimer2 = timer.performWithDelay(32000,makeCloud, 0)
end
end
I am calling
startClouds(dayNight)
in the enter scene event and the cloudInstance Table and count are initiated elsewhere in scope (as i get output to the debug prints at the top).
So my problem is that the first cloud floats across the sky, but then the second appears at the end point of the first, then each successive cloud appears in this location, with no transition.
Also it looks like I am not removing these objects properly.
I am sure i am doing something basic wrong and would really appreciate someone more experienced taking a look at this.
Thanks,
Jez [import]uid: 194492 topic_id: 35624 reply_id: 335624[/import]