AndEgine/Box2d-如何在不使用鼠标关节的情况下移动动态物体? [英] AndEgine/Box2d-How to move a dynamic body without using mouse joint?

查看:99
本文介绍了AndEgine/Box2d-如何在不使用鼠标关节的情况下移动动态物体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了很多尝试,找到了一种在屏幕上平稳移动动态物体的解决方案.鼠标关节不适用于我,它具有橡皮筋效果,对平滑运动无效.我也尝试过施加线速度来使球移动,但不能这样做.在身体上进行简单的触摸动作有哪些选择?例如,类似于发光曲棍球吗?

I have tried a lot to find a solution for moving a dynamic body smoothly on the screen. Mouse Joint doesn't work for me, it has that rubber band effect that isn't useful for smooth movements. I have also tried to apply linear velocity to make the ball move, but couldn't do it so. What are the options to get a simple touch movement on bodies? For example, similar to Glow Hockey?

答案不必特定于AndEngine. Cocos2d也将为我工作.

The answer need not to be specific to AndEngine. Cocos2d would work for me as well.

我已经注册了Touch侦听器,并尝试使用以下命令在移动"动作上移动主体:

I've registered Touch listener, and try to move the body on 'Move' Action using:

public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final ITouchArea pTouchArea, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
         switch(pSceneTouchEvent.getAction()){
         case TouchEvent.ACTION_DOWN:

             break;
            case TouchEvent.ACTION_MOVE:
                strikerBody.setLinearVelocity((pSceneTouchEvent.getX()-strikerBody.getPosition().x * PIXEL_TO_METER_RATIO_DEFAULT),(pSceneTouchEvent.getY()-strikerBody.getPosition().y * PIXEL_TO_METER_RATIO_DEFAULT));

                break;
            case TouchEvent.ACTION_UP:

                 break;
            default:
                break;
        }}

身体确实在向正确的方向移动,但是如果手指的运动快一点,随着速度的增加,它就会远离手指.

The body does move and in the right direction, but if finger movement is a little faster it runs away from the finger, as magnitude of the velocity increases.

推荐答案

不使用鼠标进行物理身体的关节运动就变得不那么容易了. 如果您更改鼠标关节定义中的某些值,那么您肯定会获得想要的效果.

Without using mouse joint movement of physics body not become as easy. If you change some value in mouse joint definition then you definitely get your desire effect.

鼠标关节的默认行为是如此有弹性.您必须根据需要进行更改. 我为您提供一套价值服务,为我工作.你检查一下自己的身边.

Default behaviour of mouse joint is so elastic. You have to change it as per your requirement. One value set, I provide to you that work for me. That you check for your side.

mouseJointDef.bodyA = this.mGroundBody;
mouseJointDef.bodyB = body;
mouseJointDef.dampingRatio = 4f;
mouseJointDef.frequencyHz = 30;
mouseJointDef.maxForce = (1000.0f * body.getMass());
mouseJointDef.collideConnected = true;

这篇关于AndEgine/Box2d-如何在不使用鼠标关节的情况下移动动态物体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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