我对 Libgdx 引擎真的很陌生。我一直在尝试让球随机移动并反弹边缘。我花了两天时间,我做不到。我只有球上下弹跳。该引擎缺乏文档,因此很难学习。任何帮助表示赞赏。
问问题
740 次
2 回答
2
一些伪代码:
If ball.radius + ball.x >= srceen.width or ball.x - ball.radius <= 0
ball.velocityx *= -1
于 2013-05-31T16:12:47.010 回答
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;
}
祝你好运。
于 2013-06-01T13:37:36.417 回答