【发布时间】:2014-03-21 22:06:03
【问题描述】:
--***************************************************
-- drawButtons() -->
--***************************************************
local flyPlane = function(event)
if event.phase == "began" and gameIsActive == true then
print("began")
physics.setGravity( 0, -10 )
elseif event.phase == "ended" and gameIsActive == true then
print("ended")
physics.setGravity( 0, 7 )
inBound = true
elseif event.phase == "moved" and gameIsActive == true then
-- do nothing
end
end
--***************************************************
-- keepPlaneInBound() -->
--***************************************************
local keepPlaneInBound = function()
-- print("checking")
if paperPlane.y <= paperPlane.height + 10 and gameIsActive == true and inBound == true then
inBound = false
paperPlane.y = paperPlane.height + 12
end
if paperPlane.y > display.contentHeight - paperPlane.height - scale.height and gameIsActive == true then
paperPlane.y = display.contentHeight - paperPlane.height - scale.height
end
end
函数 flyPlane 设置在“touch”事件列表器上,keepPlaneInBound 已设置为“enterframe”事件列表器。我想要实现的是当飞机超过上限时。它之前的 physcis.setGravity 值将被完全删除,并且当用户抬起手指时(当 event = "ended" 时)分配给它的新值。 奇怪的是它不接受新的physics.setGravity() 值。如果我使用physics.pause() 然后为其分配新的重力值。在physics.start 上,它首先完成前一个setGravity 值的部分,因此再次向上移动它......:/
【问题讨论】:
-
您的重力代码先验没有问题,不确定边界检查,因为看起来
keepPlaneInBound中有一个额外的“结束”会导致语法错误。所以请更正它并编辑您的问题以显示您注册事件回调的代码,这可能是错误所在。 -
@Schollii。嗨,谢谢你帮助我。您所说的“结束”是在这里错误添加的。我已经编辑了代码。现在代码就是它在我的记事本++中的样子了。
-
好的,但正如我所提到的,我看不出你的代码有什么问题,我什至尝试在测试应用程序中改变重力并且它工作正常,所以问题出在你没有的代码上显示。请显示您的 addEventListener 调用,以及用于调用这两个函数的任何其他代码。 "function flyPlane is set on "touch" "enterframe" eventlistner" 没有意义,需要看代码。
-
痛,@Schollii。我同意你的看法,我在问题的描述中犯了一些严重的错误。现在解决了。我已经发布了我为摆脱它所做的事情。不管怎么说,多谢拉。 :)
标签: android lua coronasdk game-engine physics