【问题标题】:corona Images in Front of cloud?云前的电晕图像?
【发布时间】:2013-05-16 11:57:21
【问题描述】:

嗨,由于某种原因,我无法让 本地直升机 = display.newImage("helicopter.png") 在云层前显示(移动背景),有什么好的方法吗?解决这个问题?

<code>
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")
</code>

谢谢

【问题讨论】:

    标签: lua coronasdk


    【解决方案1】:

    当我使用我的解决方案运行您的代码时,它起作用了。我只添加了:

    randomcloud:toBack()
    

    由于randomcloud是一个显示对象,我可以将它发送到页面的后面。

    【讨论】:

      【解决方案2】:

      最简单的解决方案是使用两个 DisplayGroup(一个用于云,一个用于直升机)按所需顺序安装在一个“根”组中。这样,您将只有一个没有组的对象 - “根”。

      http://www.coronalabs.com/blog/2012/02/28/corona-display-groups-101/

      【讨论】:

        猜你喜欢
        • 2011-12-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-16
        • 1970-01-01
        • 2015-07-25
        • 1970-01-01
        • 2014-07-23
        相关资源
        最近更新 更多