【问题标题】:Libgdx ball gameLibgdx 球类游戏
【发布时间】:2013-05-31 16:09:15
【问题描述】:

我对 Libgdx 引擎真的很陌生。我一直在尝试让球随机移动并反弹边缘。我花了两天时间,我做不到。我只有球上下弹跳。该引擎缺乏文档,因此很难学习。任何帮助表示赞赏。

【问题讨论】:

  • 我认为 libgdx 有很好的文档。谷歌一下吧..steigert.blogspot.ie/2012/02/… 是一个很好的教程...它使用了有点旧的 libgdx 0.9.2,但它会让你开始

标签: java libgdx box2d


【解决方案1】:

一些伪代码:

If ball.radius + ball.x >= srceen.width or ball.x - ball.radius <= 0
    ball.velocityx *= -1

【讨论】:

  • 如果不知道其余代码的布局、变量名等,这几乎是不可能的。尝试并实现与上述类似的系统。
【解决方案2】:

你可以试试这个:

    rev=-1;
    vy = intSpeedY;
    vx = intSpeedX;

    ball.x += vx;
    ball.y += vy;
    if (ball.x + ball.radius > right) {
      ball.x = right - ball.radius;
      vx *= rev;
    } else if (ball.x - ball.radius < left) {
      ball.x = left + ball.radius;
      vx *= rev;
    }
    if (ball.y + ball.radius > bottom) {
      ball.y = bottom - ball.radius;
      vy *= rev;
    } else if (ball.y - ball.radius < top) {
      ball.y = top + ball.radius;
      vy *= rev;
    }

祝你好运。

【讨论】:

    猜你喜欢
    • 2013-06-27
    • 2016-03-03
    • 1970-01-01
    • 2015-08-23
    • 1970-01-01
    • 1970-01-01
    • 2023-01-18
    • 2010-11-28
    • 2015-01-06
    相关资源
    最近更新 更多