2013-05-31 139 views
0

我是Libgdx引擎的新手。我一直在试图让球随机移动并且边缘反弹。这花了我两天,我无法做到。我只有球在上下跳动。这个引擎缺乏文档,所以很难学习它。任何帮助表示赞赏。Libgdx球类游戏

+0

我认为libgdx有非常好的文档。只是谷歌它.. http://steigert.blogspot.ie/2012/02/1-libgdx-tutorial-introduction.html是一个很好的教程...它使用libgdx 0.9.2这是有点旧,但它会得到你开始 –

回答

2

一些伪代码:

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

谢谢,但我想要实际的代码。 – Tareq

+3

不知道其余代码的布局,变量名等等,这几乎是不可能的。尝试并实施与上述类似的系统。 – Triclops200

1

你可以试试这个:

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; 
    } 

好运。