屏幕上移动球 - Corona

我在屏幕上制作了两个不可见的矩形,一个在左侧,一个在右侧。我有一个球在中间,当我触摸它们时,我希望它向左或向右移动。它可以工作。问题是:如果我按下其中一个,然后在此之后按下另一个(同时第一个仍然按下),它将移动到另一侧,但这并没有发生。例如:我按下右侧的矩形(球向右移动),并且它按下时我按下左侧的矩形,但是球仍然向左走。

代码:

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函数。 请有人可以帮助我吗?

点赞
用户1366533
用户1366533

在 Corona 中,你必须显式地启用多点触控事件才能使其工作。你可以通过调用以下代码来启用多点触控事件:

system.activate( "multitouch" )

参见 system.activate() 文档 来获取示例。

2015-08-25 13:33:44