停止控制对象在Corona sdk中移动

时间:2013-05-22 08:43:14

标签: corona

我有一个类似太空射击游戏的2个控件,左右两侧。 船只向左和向右移动,当船向左移动x = 40(最左边)时,它将恢复到x = 40并暂时禁用“向左移动”功能,但我的问题是每当我移动时在屏幕的最左侧或最右侧,从屏幕中间开始,船舶移动超过x = 40(大约x = 35),然后向后移动并继续直到我松开按钮。 我怎样才能这样做,以便当我将船移到最左边时,它完全停止并且只让我向右移动?

这是我的代码:

function left:touch()
if(car01.x>40 and car01.x<280) then
    motionx=-speed;
return false
end
end
left:addEventListener("touch",left)

function left:touch2()
    motionx=0;
end

local function movecar(event)
if(car01.x>40 and car01.x<280) then
    car01.x=car01.x+motionx
return false
elseif(car01.x==40) then
    car01.angularVelocity=0
    left:addEventListener("touch2",left)
    car01.x=car01.x+motionx
elseif(car01.x<40) then
    car01.x=40
end
end
Runtime:addEventListener("enterFrame",movecar)

local function stop(event)
if (event.phase=="ended") then
    motionx=0;
    return true
    end
end
Runtime:addEventListener("touch",stop)

1 个答案:

答案 0 :(得分:0)

你正在寻找的是什么??

创建背景(bg),左右控件(左右分别)。然后:

local function moveLeft()
  if(car01.x>40)then
    car01.x = car01.x - 40
  end
end
left:addEventListener("tap",moveLeft)

local function moveRight()
  if(car01.x<280)then
    car01.x = car01.x + 40
  end
end
right:addEventListener("tap",moveRight)

Keeo编码.......:)