Bug正在开发Pong Game

问题描述 投票:-2回答:1

我正在创建我的第一个游戏,Pong,我有一个小错误,我不知道如何解决。如果球从上方击中垫,则进入其内部并从另一侧退出。

这是与视频的链接,以更好地了解错误Pong Game Bug

我也会在这里发布我的代码,这样你就可以看到我是怎么做到的。

    // Ball

    ball.move(xVelocityBall, yVelocityBall);

    // Colosion for pad1
    if (ball.getGlobalBounds().intersects(pad1.getGlobalBounds()) == true)
    {
        xVelocityBall = -xVelocityBall;
        hit.play();
    }

    // Colosion for pad2
    if (ball.getGlobalBounds().intersects(pad2.getGlobalBounds()) == true)
    {
        xVelocityBall = -xVelocityBall;
        hit.play();
    }
c++ sfml
1个回答
0
投票

我认为问题在于,当你的球与打击垫相交时,你改变了速度矢量的x分量的符号,但你的球仍然在打击垫上,所以下一帧速度的标志再次改变,导致球保持卡住状态垫。

这种碰撞需要一些注意,因为你会遇到很多边缘情况。

© www.soinside.com 2019 - 2024. All rights reserved.