如何使用box2d在libgdx中拖动对象? [英] how do I drag an object in libgdx using box2d?

查看:197
本文介绍了如何使用box2d在libgdx中拖动对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将对象添加到 libgdx 中的 box2d 世界。

我想知道如果可以用鼠标拖动对象?如果是这样,怎么样?



谢谢!

解决方案

这里有几个选项。您可以使用鼠标关节,也可以使用运动体并手动设置其位置。关于如何使用鼠标关节的一个很好的例子检查这个:



http:// code。 google.com/p/libgdx-backend-android-livewallpaper/source/browse/gdx-backend-android-livewallpaper-example/src/com/badlogic/gdx/tests/box2d/Box2DTest.java?r=ba02aaf34a8ca07daa0c30493bab993067c652f9



如果你想使用运动体,你可以这样做:



在render()中: / p>

body.setTransform(Gdx.input.getX(),Gdx.input.getY(),angle);



<然后你会说body.getPosition()用于渲染你的精灵。或者,如果您使用的是调试渲染器,它将绘制您的实体,但就像形状一样。


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?

thanks!

解决方案

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-example/src/com/badlogic/gdx/tests/box2d/Box2DTest.java?r=ba02aaf34a8ca07daa0c30493bab993067c652f9

If you want to use a kinematic body you would do this:

in render():

body.setTransform(Gdx.input.getX(), Gdx.input.getY(), angle);

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中拖动对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆