大家好,我想让雪碧在我的游戏中掉下来。我在网上搜遍了所有的东西,我做到了:

    scene = new Scene();

    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) {
            mPhysicsWorld.onUpdate(pSecondsElapsed);
        }

        @Override
        public void reset() {}
    });

但是当我启动游戏的时候精灵不会掉下来!!为什么?拜托,我绝望了!啊!

最佳答案

精灵不使用物理,但身体使用物理。你应该使用物理连接器(连接你的精灵和你的身体):
设置body变量:

Body yourBody = PhysicsFactory.createBoxBody(mPhysicsWorld, main, BodyType.DynamicBody, objectFixtureDef);

然后使用这个物理连接器:
mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(main, yourBody, true, true));

对不起我的英语。

关于android - 而且发动机重力不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13224497/

10-10 06:06