如何防止随机生成的对象重叠?科罗纳sdk
[守则] [/CODE] 我首先生成建筑物,然后让它们慢慢向左移动,然后从屏幕的右侧随机生成一个循环,建筑物从左到右依次出现。 我对这些洞也做了同样的处理,但它们似乎与建筑物重叠。 如何限制它们重叠?您可以使用object:toFront或object:toBack更改显示层次结构,也可以通过为显示组设置索引号来更改显示层次结构,例如:如何防止随机生成的对象重叠?科罗纳sdk,sdk,coronasdk,Sdk,Coronasdk,[守则] [/CODE] 我首先生成建筑物,然后让它们慢慢向左移动,然后从屏幕的右侧随机生成一个循环,建筑物从左到右依次出现。 我对这些洞也做了同样的处理,但它们似乎与建筑物重叠。 如何限制它们重叠?您可以使用object:toFront或object:toBack更改显示层次结构,也可以通过为显示组设置索引号来更改显示层次结构,例如: local buildingsA= getBuildings("level1a") local buildingsB= getBuildings("level1
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)
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)