【发布时间】:2016-08-26 19:08:45
【问题描述】:
好的,所以我有一个跳转按钮和一个运行时监听函数,用于按下跳转按钮。 因此,每当按下跳跃按钮时,我都会对游戏英雄施加线性脉冲。
local function controls(event)
if(event.phase=="began") then
if (buttonpressed.id=="jump") then
hero:applyLinearImpulse(0,-10,hero.x,hero.y)
end
elseif(event.phase=="ended") then
end
end
现在的问题是,如果用户继续点击跳跃按钮,那么英雄会继续上升。我想不出什么来反驳这一点。我可以做的一件事是将上面的代码更改为:
local function controls(event)
if(event.phase=="began") then
if (buttonpressed.id=="jump" and hero.y>display.contentHeight/2) then
hero:applyLinearImpulse(0,-10,hero.x,hero.y)
end
elseif(event.phase=="ended") then
end
end
但这仍然允许跳跃按钮工作,直到达到屏幕的一半。 请帮我解决这个问题。
谢谢
【问题讨论】: