Images in Front of cloud ?

Hi i cant get ’ local helicopter = display.newImage(“helicopter.png”) ’ to display in front of the clouds, is there a good way to do this ?

function initcloud()  
 local cloud1 = {}  
 cloud1.imgpath = "cloud1.png"; --Set Image Path for cloud  
 cloud1.movementSpeed = 10000; --Determines the movement speed of cloud  
 table.insert(cloudTable, cloud1); --Insert cloud into cloudTable  
  
 local cloud2 = {}  
 cloud2.imgpath = "cloud2.png";  
 cloud2.movementSpeed = 12000;  
 table.insert(cloudTable, cloud2);   
  
 local cloud3 = {}  
 cloud3.imgpath = "cloud3.png";  
 cloud3.movementSpeed = 14000;  
 table.insert(cloudTable, cloud3);  
end --END initcloud()   
  
function getRandomcloud()  
local temp = cloudTable[math.random(1, #cloudTable)] -- Get a random cloud from cloudTable  
local randomcloud = display.newImage(temp.imgpath); --physics.addBody(randomcloud, {isSensor = true});  
randomcloud.myName = "cloud";  
randomcloud.movementSpeed = temp.movementSpeed; -- set the cloud cloudting point  
randomcloud.x = math.random(10, \_W);  
randomcloud.y = -35;  
randomcloud.rotation = math.random(0, 20); -- move the cloud  
cloudMove = transition.to(randomcloud, {  
time = randomcloud.movementSpeed,   
y = 500,  
onComplete = function(self)  
self.parent:remove(self);  
self = nil;  
end   
});  
end  
  
function cloudtGame()  
 cloudTimer1 = timer.performWithDelay(1400,getRandomcloud, 0)  
 cloudTimer2 = timer.performWithDelay(2000,getRandomcloud, 0)  
 cloudTimer3 = timer.performWithDelay(2400,getRandomcloud, 0)   
end--END cloudtGame()  
  
initcloud()  
cloudtGame()  
  
local helicopter = display.newImage("helicopter.png")  
  

Thank you [import]uid: 225288 topic_id: 35776 reply_id: 335776[/import]

If you put both the cloud and the helicopter into a display group and then send the helicopter to the font

-like so

[lua]
group = display.newGroup()
group:insert(helicopter)
group:insert(cloud)
helicopter:toFront() [import]uid: 113909 topic_id: 35776 reply_id: 142316[/import]

Or use two groups, one for helicopter(s) and one for clouds.

[code]
local cloudGroup = display.newGroup()
local heliGroup = display.newGroup()

function createClouds()

cloudGroup:insert(cloud1)
cloudGroup:insert(cloud2)
cloudGroup:insert(cloud3)
end

function createHelicopter()

heliGroup:insert(helicopter)
end
– Now order of creation and insertion doesn’t matter, as long as you
– created the groups in the right order, the first created will behind
– the second created and so on.

createHelicopter()
createClouds()
[/code] [import]uid: 110228 topic_id: 35776 reply_id: 142317[/import]

Hi Emaurina,
I have tried this but the helicopter is still behind the clouds what am i doing wrong…it is driving me mad

local cloudGroup = display.newGroup()  
local heliGroup = display.newGroup()  
heliGroup:toFront()  
  
function createClouds()  
 cloudGroup:insert(cloud1)  
 cloudGroup:insert(cloud2)  
 cloudGroup:insert(cloud3)  
end  
  
function createHelicopter()  
 local helicopter = display.newImage("helicopter.png")  
end  
   
createClouds()  
createHelicopter()  

Thank you for the help [import]uid: 225288 topic_id: 35776 reply_id: 142347[/import]

try putting the heliGroup:toFront() line at the bottom of your code, pretty sure that will make it work.
Just ask if you are having any more trouble
-Boxie [import]uid: 113909 topic_id: 35776 reply_id: 142440[/import]

@mmk.verheijden,

Sorry for the delay…

The code you pasted is missing one key element. I don’t see you inserting the helicopter into its group:

local cloudGroup = display.newGroup()  
local heliGroup = display.newGroup()  
heliGroup:toFront()  
   
function createClouds()  
 cloudGroup:insert(cloud1)  
 cloudGroup:insert(cloud2)  
 cloudGroup:insert(cloud3)  
end  
   
function createHelicopter()  
 local helicopter = display.newImage("helicopter.png")  
 heliGroup:insert(helicopter) --- MISSING THIS CODE  
end  
   
createClouds()  
createHelicopter()  

The code you posted would create the helicopter in the current stage (primary parent) and that is behind both cloud and helicopter groups.

[import]uid: 110228 topic_id: 35776 reply_id: 142524[/import]

If you put both the cloud and the helicopter into a display group and then send the helicopter to the font

-like so

[lua]
group = display.newGroup()
group:insert(helicopter)
group:insert(cloud)
helicopter:toFront() [import]uid: 113909 topic_id: 35776 reply_id: 142316[/import]

Or use two groups, one for helicopter(s) and one for clouds.

[code]
local cloudGroup = display.newGroup()
local heliGroup = display.newGroup()

function createClouds()

cloudGroup:insert(cloud1)
cloudGroup:insert(cloud2)
cloudGroup:insert(cloud3)
end

function createHelicopter()

heliGroup:insert(helicopter)
end
– Now order of creation and insertion doesn’t matter, as long as you
– created the groups in the right order, the first created will behind
– the second created and so on.

createHelicopter()
createClouds()
[/code] [import]uid: 110228 topic_id: 35776 reply_id: 142317[/import]

Hi Emaurina,
I have tried this but the helicopter is still behind the clouds what am i doing wrong…it is driving me mad

local cloudGroup = display.newGroup()  
local heliGroup = display.newGroup()  
heliGroup:toFront()  
  
function createClouds()  
 cloudGroup:insert(cloud1)  
 cloudGroup:insert(cloud2)  
 cloudGroup:insert(cloud3)  
end  
  
function createHelicopter()  
 local helicopter = display.newImage("helicopter.png")  
end  
   
createClouds()  
createHelicopter()  

Thank you for the help [import]uid: 225288 topic_id: 35776 reply_id: 142347[/import]

try putting the heliGroup:toFront() line at the bottom of your code, pretty sure that will make it work.
Just ask if you are having any more trouble
-Boxie [import]uid: 113909 topic_id: 35776 reply_id: 142440[/import]

@mmk.verheijden,

Sorry for the delay…

The code you pasted is missing one key element. I don’t see you inserting the helicopter into its group:

local cloudGroup = display.newGroup()  
local heliGroup = display.newGroup()  
heliGroup:toFront()  
   
function createClouds()  
 cloudGroup:insert(cloud1)  
 cloudGroup:insert(cloud2)  
 cloudGroup:insert(cloud3)  
end  
   
function createHelicopter()  
 local helicopter = display.newImage("helicopter.png")  
 heliGroup:insert(helicopter) --- MISSING THIS CODE  
end  
   
createClouds()  
createHelicopter()  

The code you posted would create the helicopter in the current stage (primary parent) and that is behind both cloud and helicopter groups.

[import]uid: 110228 topic_id: 35776 reply_id: 142524[/import]