精灵碰撞和引擎
Sprite collision AndEngine
我想更新精灵的位置。但它正在向下移动然后跳跃一点然后停止。它甚至不会向左或向右移动。我希望它根据倾斜度向左、向右、向上和向下移动。
这是我的代码:-
Scene scene = new Scene();
scene.setBackground(new Background(1.09804f, 0.6f, 3.0f));
playerSprite = new AnimatedSprite(10, 10, 48, 64, pTextureRegion, getVertexBufferObjectManager());
playerSprite.animate(300);
PhysicsWorld physicsWorld = new PhysicsWorld(new Vector2( 0, SensorManager.GRAVITY_MOON), false);
FixtureDef PLAYER_FIX = PhysicsFactory.createFixtureDef(10.0f, 0.5f, 0.0f);
Body playerBody = PhysicsFactory.createBoxBody(physicsWorld, playerSprite, BodyType.DynamicBody, PLAYER_FIX);
physicsWorld.registerPhysicsConnector(new PhysicsConnector(playerSprite, playerBody, true, false));
scene.attachChild(playerSprite);
在你的
PhysicsWorld physicsWorld = new PhysicsWorld(new Vector2( 0, SensorManager.GRAVITY_MOON), false);
将 SensorManager.Gravity_Moon 更改为 .Sensor_Orientation,这使得所有物体的重力都指向下方。我不确定你到底要选择哪一个,但这是你的问题。试试其他的。Sensor_xxx 如果我告诉你的那个不起作用。
public void onAccelerationChanged(AccelerationData pAccelerationData) {
// TODO Aiuto-generated method stub
Vector2 gravity = Vector2Pool.obtain(pAccelerationData.getX(), pAccelerationData.getY());
this.physicsWorld.setGravity(gravity);;
Vector2Pool.recycle(gravity);
我想更新精灵的位置。但它正在向下移动然后跳跃一点然后停止。它甚至不会向左或向右移动。我希望它根据倾斜度向左、向右、向上和向下移动。 这是我的代码:-
Scene scene = new Scene();
scene.setBackground(new Background(1.09804f, 0.6f, 3.0f));
playerSprite = new AnimatedSprite(10, 10, 48, 64, pTextureRegion, getVertexBufferObjectManager());
playerSprite.animate(300);
PhysicsWorld physicsWorld = new PhysicsWorld(new Vector2( 0, SensorManager.GRAVITY_MOON), false);
FixtureDef PLAYER_FIX = PhysicsFactory.createFixtureDef(10.0f, 0.5f, 0.0f);
Body playerBody = PhysicsFactory.createBoxBody(physicsWorld, playerSprite, BodyType.DynamicBody, PLAYER_FIX);
physicsWorld.registerPhysicsConnector(new PhysicsConnector(playerSprite, playerBody, true, false));
scene.attachChild(playerSprite);
在你的
PhysicsWorld physicsWorld = new PhysicsWorld(new Vector2( 0, SensorManager.GRAVITY_MOON), false);
将 SensorManager.Gravity_Moon 更改为 .Sensor_Orientation,这使得所有物体的重力都指向下方。我不确定你到底要选择哪一个,但这是你的问题。试试其他的。Sensor_xxx 如果我告诉你的那个不起作用。
public void onAccelerationChanged(AccelerationData pAccelerationData) {
// TODO Aiuto-generated method stub
Vector2 gravity = Vector2Pool.obtain(pAccelerationData.getX(), pAccelerationData.getY());
this.physicsWorld.setGravity(gravity);;
Vector2Pool.recycle(gravity);