Event.target只碰撞一次,而不是多次碰撞

时间:2015-07-23 20:40:30

标签: lua corona

当我运行onCollision函数时,它似乎多次与'ground'碰撞,即使它没有移动。一旦物体撞到地面,它怎么能这样做呢?它只与它“碰撞”一次?

我想在每次击中时都给出一个“得分”,但由于它多次击中地面,我的得分似乎一直在上升。

这是代码的一部分:

function playerCollision( self, event )
    if ( event.phase == "began" ) then
        --if hit bottom column, u get points
        if event.target.type == "player" and event.other.type == "bottomColumn" then
            print ("hit column")
            onPlatform = true


        else
        --if hit anything else, gameOver
            --composer.gotoScene( "restart" )

            print ("hit ground")
        end
    end
end

1 个答案:

答案 0 :(得分:0)

我没有发现您的代码有任何问题,只是尝试添加此声明,希望它可能有用。

function playerCollision( self, event )
   if ( event.phase == "began" ) then
    --if hit bottom column, u get points
     if event.target.type == "player" and event.other.type == "bottomColumn" then
        print ("hit column")
        onPlatform = true
        return true -- try adding this 

    else
    --if hit anything else, gameOver
        --composer.gotoScene( "restart" )

        print ("hit ground")
    end
end

相关问题