【发布时间】:2013-12-08 07:27:25
【问题描述】:
我有一个水图像,它在碰撞时杀死用户精灵,从生命变量中取 1 并重新生成精灵到开始。我有另一个木筏的图像,它不断产生在屏幕上移动的新图像。我试图得到它,以便用户可以移动到木筏上,即在水上图像上方,而不是重新生成回到开始。
--sets the function for the death sequence.
function waterCollide(event)
frog.x = display.contentWidth/2
frog.y = 504
isOnRaft = 0
lives = lives - 1
showlives.text = "Lives: "..lives,230,-36,native.systemFont,25
lose()
end
--sets water
water = display.newRect(0,0,320,150)
water.x = display.contentWidth*0.5
water.y = 144
water.alpha = 0
physics.addBody(water,"static", {isSensor = true})
water:addEventListener("collision", function ()timer.performWithDelay(50,waterCollide)end)
--Set log position and movement
local mRandom = math.random
local raft = {"Raft1" ,"Raft2"}
local objectTag = 0
local object = {}
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(3500,spawnlogleft,0)
--user sprite details
frog = display.newSprite(frogSheet, sequenceData)
frog.x = display.contentWidth/2
frog.y = 504
physics.addBody( frog, "dynamic", physicsData:get("FrogSheetData"))
frog.isFixedRotation = true
用户精灵是一个三帧动画,时间为 300。任何帮助将不胜感激。如果需要,我会提供更多详细信息。
谢谢你
【问题讨论】:
-
这和你问的other question有什么不同?
-
因为我在没有动画的情况下工作,而当我只有固定的日志时。如果我出于某种原因在筏上使用 isOnRaft = 1,则它等于 24。
标签: lua collision-detection coronasdk physics