Chipmunk 模拟时拖动 Sprite (Cocos2D)

发布于 2024-08-30 14:58:44 字数 431 浏览 4 评论 0原文

我有一个用 Cocos2D 和 Chipmunk 构建的简单项目。到目前为止,它只是一个在地面(屏幕底部的静态线段)上弹跳的球(主体、形状和精灵)。

我实现了 ccTouchesBegan/Moved/Ended 方法来拖动球。 我已经尝试过这两种方法:

cpBodySlew(ballBody, touchPoint, 1.0/60.0f);

虽然

ballBody->p = cgPointMake(touchPoint.x,touchPoint.y);

球确实跟随我的拖动,但它仍然受到重力的影响,并且它试图下降(这会导致速度问题和其他问题)。

有谁知道在物理模拟进行时拖动活动物体的首选方法? 我是否需要以某种方式停止模拟并随后将其重新打开?

谢谢!

I have a simple project built with Cocos2D and Chipmunk. So far it's just a Ball (body, shape & sprite) bouncing on the Ground (a static line segment at the bottom of the screen).

I implemented the ccTouchesBegan/Moved/Ended methods to drag the ball around.
I've tried both:

cpBodySlew(ballBody, touchPoint, 1.0/60.0f);

and

ballBody->p = cgPointMake(touchPoint.x,touchPoint.y);

and while the Ball does follow my dragging, it's still being affected by gravity and it tries to go down (which causes velocity problems and others).

Does anyone know of the preferred way to Drag an active Body while the physics simulation is going on?
Do I need somehow to stop the simulation and turn it back on afterwards?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

掩耳倾听 2024-09-06 14:58:44

暂时将尸体移出空间。

如果您希望物体在释放时具有惯性,那就是另一回事了。最简单的方法是在球和临时传感器主体之间连接一个相当硬的弹簧,该传感器在手指的控制下移动。当您松开手指时,球将保留您拖动它时所具有的任何运动学。在这种情况下,请务必不要将球从空间中移出。

Temporarily remove the body from the space.

If you want the object to have inertia when you release it, that's a different story. The cleanest way is to attach a fairly stiff spring between the ball and a temporary sensor body that moves under the control of your finger. When you let go with your finger, the ball will retain whatever kinematics it had while you were dragging it. Be sure not to remove the ball from the space in this case.

第七度阳光i 2024-09-06 14:58:44

当您不使用 cpBodySlew() 时,您不会更新对象的速度。这就是为什么它会直接掉下来。

更好的方法是像官方演示一样使用力夹紧的枢轴关节来实现鼠标控制。 http://code.google。 com/p/chipmunk-physicals/source/browse/trunk/Demo/ChipmunkDemo.c#296

You aren't updating the velocity of the object when you aren't using cpBodySlew(). That is why it falls straight down.

A better way to do it is to use a force clamped pivot joint like the official demos do to implement mouse control. http://code.google.com/p/chipmunk-physics/source/browse/trunk/Demo/ChipmunkDemo.c#296

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文