2

大家好,我正试图让一个精灵落在我的游戏中。我搜索了整个网络,我这样做了:

    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() {}
    });

但是当我启动游戏时,精灵并没有掉下来!为什么 ??请让我绝望!!

4

1 回答 1

3

Sprite 不使用物理,但 body 使用。您应该使用物理连接器(将您的精灵与您的身体连接起来):

设置主体变量:

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

然后使用这个物理连接器:

mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(main, yourBody, true, true));

对不起我的英语不好。

于 2012-11-05T05:59:59.953 回答