大家好,我正在尝试开发像 Jetpack 这样的游戏,所以我想设置一个通常向下推的重力,当用户点击屏幕时,重力会改变它向上推。我搜索了一周的教程来解释如何做到这一点,但我没有找到我搜索的内容。有人可以向我解释如何做到这一点或发布教程链接吗?
谢谢 !!
main = new Sprite(sX, sY, mainTextureRegion);
main.setScale(1);
main.setFlippedHorizontal(true);
scene.attachChild(main);
mPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);
final FixtureDef objectFixtureDef = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f);
final Body body = PhysicsFactory.createBoxBody(mPhysicsWorld, main, BodyType.DynamicBody, objectFixtureDef);
mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(main, body, true, true));
final Vector2 gravity = new Vector2(0, 5f);
mPhysicsWorld.setGravity(gravity);
scene.registerUpdateHandler(new IUpdateHandler() {
@Override
public void onUpdate(float pSecondsElapsed) {
}
@Override
public void reset() {
// TODO Auto-generated method stub
}});