1

[代码]

local buildingsA= getBuildings("level1a")
local buildingsB= getBuildings("level1b")
local buildingsC= getBuildings("level1c")

buildingsA.x=1100
buildingsB.x=buildingsA.x+buildingsA.width+300
buildingsC.x=buildingsB.x+buildingsB.width+350
--END OF LEVEL1 CREATION

timer.performWithDelay(1, function(e)
    buildingsA.x = buildingsA.x -15
    buildingsB.x = buildingsB.x-15
    buildingsC.x = buildingsC.x-15
    end, 0 )    

function scrollblocks(self, event)
    if self.x <-100 then
        self.x=math.random(1200,2000) 
    end
end
buildingsA.enterFrame= scrollblocks
buildingsB.enterFrame= scrollblocks
buildingsC.enterFrame= scrollblocks

Runtime:addEventListener("enterFrame", buildingsA)
Runtime:addEventListener("enterFrame", buildingsB)
Runtime:addEventListener("enterFrame", buildingsC)

--Add hole
local hole = display.newImage("hole.png", true)
    physics.addBody(hole, "static", {friction= 0.5, bounce=0})
    hole.y=floor_bottom.y-60
    hole.x= buildingsA.x+100

timer.performWithDelay(1, function(e) 
    hole.x= hole.x-15 
    end, 0 )    

hole.enterFrame=scrollblocks
Runtime:addEventListener("enterFrame", hole)

[/代码]

我先生成建筑物,然后让它们慢慢地向左移动,然后从屏幕右侧随机生成,从而出现一个循环,建筑物从左到右出现。我对孔做同样的事情,但它们似乎与建筑物重叠。我如何限制它们重叠?

4

1 回答 1

0

您可以使用object:toFront()object:toBack()更改显示层次结构,也可以通过为显示组设置索引号来更改它,例如:

 displayGroup = display.newGroup()
 object1 = display.newImage("img1.png")
 object2 = display.newImage("img2.png")
 object3 = display.newImage("img3.png")

--inserting object to display group using index
 group:insert(1,object1)
 group:insert(2,object2)
 group:insert(3,object3)
于 2013-08-12T05:18:37.490 回答