0
我有四排隨機產生的木筏,移動到屏幕的上方,然後消失。然後在木筏下面有水圖像。我做到了這一點,當用戶走上筏子否定水域重新生成功能。但是,如果只適用於每排產卵的第一排筏。將event.phase添加到隨機生成的對象上。
local mRandom = math.random
local raft = {"Raft1" ,"Raft2","Raft3"}
local objectTag = 0
local object = {}
function spawnlogright()
objectTag = objectTag + 1
local objIdx = mRandom(#raft)
local objName = raft[objIdx]
object[objectTag] = display.newImage(objName..".png")
object[objectTag].x = 416
object[objectTag].y = 72
object[objectTag].name = objectTag
transition.to(object[objectTag], {time = 10000, x = -96, onComplete = function(obj) obj:removeSelf(); obj = nil; end})
physics.addBody(object[objectTag], "static", {isSensor = true})
end
spawnlogright()
timer.performWithDelay(3000,spawnlogright,0)
function spawnlogright()
objectTag = objectTag + 1
local objIdx = mRandom(#raft)
local objName = raft[objIdx]
object[objectTag] = display.newImage(objName..".png")
object[objectTag].x = 416
object[objectTag].y = 168
object[objectTag].name = objectTag
transition.to(object[objectTag], {time = 10000, x = -96, onComplete = function(obj) obj:removeSelf(); obj = nil; end})
physics.addBody(object[objectTag], "static", {isSensor = true})
end
spawnlogright()
timer.performWithDelay(3000,spawnlogright,0)
function spawnlogleft()
objectTag = objectTag + 1
local objIdx = mRandom(#raft)
local objName = raft[objIdx]
object[objectTag] = display.newImage(objName..".png")
object[objectTag].x = -96
object[objectTag].y = 120
object[objectTag].name = objectTag
transition.to(object[objectTag], {time = 10000, x = 416, onComplete = function(obj) obj:removeSelf(); obj = nil; end})
physics.addBody(object[objectTag], "static", {isSensor = true})
end
spawnlogleft()
timer.performWithDelay(3000,spawnlogleft,0)
function spawnlogleft()
objectTag = objectTag + 1
local objIdx = mRandom(#raft)
local objName = raft[objIdx]
object[objectTag] = display.newImage(objName..".png")
object[objectTag].x = -96
object[objectTag].y = 216
object[objectTag].name = objectTag
transition.to(object[objectTag], {time = 10000, x = 416, onComplete = function(obj) obj:removeSelf(); obj = nil; end})
physics.addBody(object[objectTag], "static", {isSensor = true})
end
spawnlogleft()
timer.performWithDelay(3000,spawnlogleft,0)
--while the frog is on the log...
function raftCollide(event)
if (event.phase == "began") then
isOnRaft = isOnRaft + 1
elseif (event.phase == "ended")then
isOnRaft = isOnRaft - 1
end
end
--add event for 'walking on the log'
object[objectTag]:addEventListener("collision",raftCollide)
我如何得到它,這樣最後一個事件監聽器會檢測所有筏
非常感謝。工作。花了數小時試圖找到解決辦法。我對盧亞頗爲陌生 – Ross