做一个机构,它连续移动 [英] make a body which moves continuously
问题描述
我是箱-2D &放工作; AndEngine 。我有动感的车身可以说一个平面。我想用一个给定的速度连续移动这一点。所以,我设置了线速度吧。我有屏幕边界(地面,屋顶,左,放大器;右墙)为好。这些都是静态的身体。当我的面与边界碰撞一至两次,这成为停止。我申请没有重力飞机。为什么飞机停尽管它有固定的速度?
问题:
我该如何与移动的速度连续以及相应方向的飞机后发生冲突?从那以后,我想去的地方的用户触摸屏幕上移动?
I am working with Box-2d & AndEngine. I have dynamic body lets say a Plane. I want to moves this continuously with a given velocity. So, I set a linear Velocity to it. I have screen boundary(ground,roof,left & Right Wall) as well. Those are static body. When my plane collides with boundaries one or two times, it's becomes stopped. I apply no gravity to plane. Why plane stopped though it has fixed velocity? Problem: How I move the plane with continuous speed as well as corresponding direction after collide ? After that I want to move it where the user touches on the screen?
code :创建平面
FixtureDef FIXTURE_DEF = PhysicsFactory
.createFixtureDef(1, .5f, 0.5f);
aPlane = new Plane(222, 333, pilotTexures, vbom) {
@Override
protected void onManagedUpdate(float pSecondsElapsed) {
super.onManagedUpdate(pSecondsElapsed);
}
};
planeBody = PhysicsFactory.createBoxBody(this.mPhysicsWorld, aPlane,
BodyType.DynamicBody, FIXTURE_DEF);
mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(
aPlane, planeBody, true, true));
planeBody.setLinearVelocity(DEMO_VELOCITY_X, DEMO_VELOCITY_Y);
attachChild(aPlane);
planeBody.setGravityScale(0);
planeBody.setUserData(PLANE);
code :建立界墙
final Rectangle ground = new Rectangle(0, camera_Height - 2,
camera_Width, 2, vbom);
final Rectangle roof = new Rectangle(0, 0, camera_Width, 2, vbom);
final Rectangle left = new Rectangle(0, 0, 2, camera_Height, vbom);
final Rectangle right = new Rectangle(camera_Width - 2, 0, 2,
camera_Height, vbom);
final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0,
0.5f, 0.5f);
PhysicsFactory.createBoxBody(this.mPhysicsWorld, ground,
BodyType.StaticBody, wallFixtureDef);
Body roofBody = PhysicsFactory.createBoxBody(this.mPhysicsWorld, roof,
BodyType.StaticBody, wallFixtureDef);
roofBody.setUserData(ROOF);
PhysicsFactory.createBoxBody(this.mPhysicsWorld, left,
BodyType.StaticBody, wallFixtureDef);
PhysicsFactory.createBoxBody(this.mPhysicsWorld, right,
BodyType.StaticBody, wallFixtureDef);
attachChild(ground);
attachChild(roof);
attachChild(left);
attachChild(right);
我也创建 ContactListener ,可当他们碰撞听。要移动手指触摸的点我也农具的 IOnSceneTouchListener
I also create ContactListener, can listen when they collide . To move on finger touched point I also implements IOnSceneTouchListener
感谢在前进。
推荐答案
你能尽你壁的弹性设置为1.0F,并定期删除联系人的摩擦,
Could you try setting the elasticity of your walls to 1.0f and for regular contact remove the friction,
final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0,
0.5f, 0.0f);
要
final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0,
1.0f, 0.0f);
合这有助于。
这篇关于做一个机构,它连续移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!