how do I drag an object in libgdx using box2d?(如何使用 box2d 在 libgdx 中拖动对象?)
问题描述
我已将对象添加到 libgdx
中的 box2d
世界.
我想知道是否可以用鼠标拖动对象?如果是这样,怎么做?
I have added objects to a box2d
world in libgdx
.
I am wondering if it was possible to drag objects with the mouse? If so, how?
谢谢!
推荐答案
这里有几个选项.您可以使用鼠标关节,也可以使用运动体并手动设置其位置.如何使用鼠标关节的一个很好的例子看看这个:
There are a couple of options here. You can use a mouse joint or you can use a kinematic body and set it's position manually. A good example of how to use a mouse joint check this out:
http://code.google.com/p/libgdx-backend-android-livewallpaper/source/browse/gdx-backend-android-livewallpaper-示例/src/com/badlogic/gdx/tests/box2d/Box2DTest.java?r=ba02aaf34a8ca07daa0c30493bab993067c652f9
如果您想使用运动体,您可以这样做:
If you want to use a kinematic body you would do this:
在渲染()中:
body.setTransform(Gdx.input.getX(), Gdx.input.getY(), 角度);
body.setTransform(Gdx.input.getX(), Gdx.input.getY(), angle);
然后你会说 body.getPosition() 来渲染你的精灵.或者,如果您正在使用调试渲染器来绘制您的身体,但只是绘制形状.
And then you would say body.getPosition() for the rendering of your sprites. Or if you are using the debug renderer that will draw your bodies, but just as shapes.
这篇关于如何使用 box2d 在 libgdx 中拖动对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 box2d 在 libgdx 中拖动对象?


- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 转换 ldap 日期 2022-01-01
- 获取数字的最后一位 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01