【问题标题】:Moving a ball on screen - cororna在屏幕上移动球 - 电晕
【发布时间】:2015-08-22 19:25:38
【问题描述】:

我在屏幕上制作了两个不可见的矩形。一个在左侧,一个在右侧。我在中间有一个球,我希望它在我触摸它们时向左或向右移动。有用。问题:我希望如果我按下其中一个,然后再按下另一个(虽然第一个仍然按下),它会移动另一侧,但没有发生。例如:我按下右侧矩形(球向右移动),按下时我按下左侧矩形,但球仍然向左移动。

代码:

function moveLeft( e )
    if (circle.x>_W*0.031 ) then
    if (e.phase=="began") then
    circle:setLinearVelocity( -800*v_circle, 0 )
    end
    if (e.phase=="ended") then
    circle:setLinearVelocity( 0, 0 )
    end 
    if (e.x>_W*0.44) then
    circle:setLinearVelocity( 0, 0 )
    end
end
end

function moveRight( e )
    if (circle.x<_W*0.969) then
    if (e.phase=="began") then
    circle:setLinearVelocity( 800*v_circle, 0 )
    end
    if (e.phase=="ended") then
    circle:setLinearVelocity( 0, 0 )
    end 
    if (e.x<_W*0.556) then
    circle:setLinearVelocity( 0, 0 )
    end
    end
end

    clickLeft = display.newRect( _W*0.212, _H/2, _W*0.7, _H*1.2 )
    clickRight = display.newRect( _W*0.78, _H/2, _W*0.7, _H*1.2 )
    clickLeft.isVisible = false
    clickRight.isVisible = false
    clickLeft:addEventListener( "touch", moveLeft )
    clickRight:addEventListener( "touch", moveRight )

我发现了更多 - 我已将此代码放在 moveLeft 函数中:(在 **** 之间)

function moveLeft( e )
    if (circle.x>_W*0.031 ) then
    if (e.phase=="began") then
    circle:setLinearVelocity( -800*v_circle, 0 )
    **** txt = display.newText("@@@@@@@", _W/2, _H*0.57, "Wekar" , 115 ) ****
    end
    if (e.phase=="ended") then
    circle:setLinearVelocity( 0, 0 )
    end 
    if (e.x>_W*0.44) then
    circle:setLinearVelocity( 0, 0 )
    end
end
end

如果我按下右边的矩形,然后再按下左边(虽然第一个仍然按下),它什么也不显示。 也就是说,在这种情况下,它甚至不会进入 moveLefr 函数。 请问有人可以帮助我吗?

【问题讨论】:

    标签: lua touch coronasdk move phase


    【解决方案1】:

    您必须在 Corona 中显式启用多点触控事件才能使其正常工作。 您可以通过调用来启用它:

    system.activate( "multitouch" )
    

    有关示例,请参阅 system.activate() documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多