Event.target只会发生一次碰撞,而不是多次。

当我运行 onCollision 函数时,似乎它与“地面”发生多次碰撞,即使它不动。如何使一旦物体撞击地面,它只与它“碰撞一次”?

我想每次它触地时都给出一个“分数”,但由于它多次碰撞地面,我的得分似乎不断增加。

下面是代码的一部分:

function playerCollision( self, event )
    if ( event.phase == "began" ) then
        --如果撞到底部的圆柱,您会得分
        if event.target.type == "player" and event.other.type == "bottomColumn" then
            print ("撞到圆柱")
            onPlatform = true

        else
        --如果撞到其他任何东西,游戏结束
            --composer.gotoScene("restart")

            print ("撞到地面")
        end
    end
end
点赞
用户2653067
用户2653067
我在你的代码中没有发现任何问题,只是尝试添加这个语句,希望它能起作用。

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 -- 尝试添加这个

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

    print ("hit ground")
end

end

```

end

2015-07-24 06:45:53