[英]Libgdx ball game
I'm really new to Libgdx engine. 我真的是Libgdx引擎的新手。 I've been trying to make a ball move randomly and bounce of the edges.
我一直在尝试使球随机移动并弹跳边缘。 It took me two days and I couldn't do it.
我花了两天,但我做不到。 I only have the ball bouncing up and down.
我只有球上下弹跳。 There is a lack of documentation for this engine, so it's difficult to learn it.
该引擎缺少文档,因此很难学习。 Any help is appreciated.
任何帮助表示赞赏。
Some pseudocode: 一些伪代码:
If ball.radius + ball.x >= srceen.width or ball.x - ball.radius <= 0
ball.velocityx *= -1
you can try this: 您可以尝试以下方法:
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;
}
good luck. 祝好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.