Box2D 世界大小
我创建了一个 box2d 世界,我想限制世界的高度。 我确实搜索了谷歌,显然在 box2d 的早期版本中有一个选项,你必须定义你的世界的大小,但我不确定你是否能够设置世界的高度,但在当前版本中他们有完全取消了该选项。
所以我只是在寻找一种限制高度的方法,因为我的球员是一个上下跳跃的球,我想限制它能跳多高(跳跃是由物理、重力和球的速度完成的,所以经过几次良好的跳跃后,随着速度的增加,球跳得非常高,我不想限制速度)并在假设y=900
上放置边界。
I have created a box2d world, and I wanted to limit the height of the world.
I did search google and apparently there was an option in the previous version of box2d where you would have to define the size of your world, but I am not sure if you were able set the height of the world but in the current version they have taken that option completely off.
So I am just looking for a way to limit the height, as my player is a ball that jumps up and down and I want to limit how high it can jump (the jumps are done by physics and gravity and the speed of the ball so after a few good jumps, the ball jumps really high as its speed increases and I dont want to limit the speed) and put border on let say y=900
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Box2D 世界的大小是无限的。您无法限制世界,但可以创建一个包围 Box2D 世界中特定区域的形状。
下面介绍了如何创建将形状放置在屏幕周围的主体和形状,以便对象不会离开屏幕。通过更改角坐标以适应您的需要,可以轻松地调整此代码:
注意:此代码适用于 Box2D v2.2.1。我认为这就是您正在使用的,因为您说的是“以前的版本”,它要求以不同的方式编写此代码(使用 SetAsEdge 方法)。
The Box2D world has an infinite size. You can't limit the world, but you can create a shape that encloses a certain area in the Box2D world.
Here's how to create a body and shape that puts a shape just around the screen, so that objects don't leave the screen. It is easy to adapt this code by changing the corner coordinates to fit whatever you need:
Note: this code is for Box2D v2.2.1. I assume that's what you're using because you said "previous version" which required this code to be written differently (with the SetAsEdge method).