Android中如何使用鼠标关节?
我想在 Android 上使用 Java 中的 MouseJoint。我是 box2d 和 cocos2d 的新手。我不知道如何使用鼠标关节。
I want to use the MouseJoint in Java for Android. I am new in box2d and cocos2d. I don't know how to use the mouse joint.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您查看 这个教程示例。从中复制(抱歉,我不喜欢损坏的链接:))...
你在 MouseJoint 的帮助下拖动你的身体,它会与世界上的其他身体发生碰撞并对它们施加力。
Box2d - 手册 - http://www.box2d.org/manual.html#_Toc258082974
8.10 鼠标关节
鼠标关节在测试台中用于通过鼠标操作物体。它尝试将主体上的点移向光标的当前位置。轮换没有限制。
鼠标关节定义具有目标点、最大力、频率和阻尼比。目标点最初与主体的锚点重合。最大力用于防止多个动态体相互作用时发生剧烈反应。您可以将其设置为任意大。频率和阻尼比用于产生类似于距离接头的弹簧/阻尼效果。
许多用户尝试过调整鼠标关节来玩游戏。用户往往希望实现精确定位和瞬时响应。鼠标关节在这种情况下不能很好地工作。您可能希望考虑使用运动体。
那么让我们开始吧..
- MouseJoint 方法
- 触摸身体
我们必须重写 onAreaTouched 方法以在触摸位置上创建 MouseJoint 锚点。
- 移动身体
我们正在场景上移动手指,因此我们也必须移动 MouseJoint。
如果我们松开手指..我们必须销毁MouseJoint..
仅供参考:
为了满足您的需求,您必须使用此设置(在 createMouseJoint 方法中)
i recomend you to see this tutorial example. Copy from it (sorry i don't like broken links :) ) ...
you drag your body with the help of the MouseJoint, it will collide with the other bodys in the world and apply force to them.
Box2d - Manual - http://www.box2d.org/manual.html#_Toc258082974
8.10 Mouse Joint
The mouse joint is used in the testbed to manipulate bodies with the mouse. It attempts to drive a point on a body towards the current position of the cursor. There is no restriction on rotation.
The mouse joint definition has a target point, maximum force, frequency, and damping ratio. The target point initially coincides with the body’s anchor point. The maximum force is used to prevent violent reactions when multiple dynamic bodies interact. You can make this as large as you like. The frequency and damping ratio are used to create a spring/damper effect similar to the distance joint.
Many users have tried to adapt the mouse joint for game play. Users often want to achieve precise positioning and instantaneous response. The mouse joint doesn’t work very well in that context. You may wish to consider using kinematic bodies instead.
So let's start..
- MouseJoint method
- Touching Body
we have to override our onAreaTouched method to create an MouseJoint anchor-point on the touch position.
- Moving the body
We are moving our finger over the scene, so we have to move the MouseJoint too.
If we release the finger.. we must destroy the MouseJoint..
FYI:
To fit your needs, you have to play with this settings ( in the createMouseJoint method )