我对Libgdx引擎真的很陌生。我一直在尝试让一个球随机移动并在边缘反弹。这花了我两天的时间,但我做不到。我只能让球上下弹跳。这个引擎缺少相关文档,所以很难学习。任何帮助都是非常感谢的。
发布于 2013-06-01 00:12:47
一些伪代码:
If ball.radius + ball.x >= srceen.width or ball.x - ball.radius <= 0
ball.velocityx *= -1发布于 2013-06-01 21:37:36
您可以尝试这样做:
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;
}祝好运。
https://stackoverflow.com/questions/16861566
复制相似问题