0

这是我的“public void create()”的一部分:

overallTexture = new Texture(Gdx.files.internal("data/sprite1.png"));
overallTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
jumperSprite = new Sprite(overallTexture, 0, 0, 32, 37);
spriteBatch = new SpriteBatch();
world = new World(new Vector2(0.0f, -10.0f), true);

    BodyDef jumperBodyDef = new BodyDef();
    jumperBodyDef.type = BodyDef.BodyType.DynamicBody;
    jumperBodyDef.position.set(1.0f, 3.0f);

    jumper = world.createBody(jumperBodyDef);
    PolygonShape jumperShape = new PolygonShape();
    jumperShape.setAsBox(jumperSprite.getWidth() / (2 * PIXELS_PER_METER),
    jumperSprite.getHeight() / (2 * PIXELS_PER_METER));

    jumper.setFixedRotation(true);

    FixtureDef jumperFixtureDef = new FixtureDef();
    jumperFixtureDef.shape = jumperShape;
    jumperFixtureDef.density = 1.0f;
    jumperFixtureDef.friction = 5.0f;

这是我的“公共无效渲染()”的一部分

if (jumper.getPosition().y < 0.4) {

        overallTexture = new      Texture(Gdx.files.internal("data/sprite1.png"));
        overallTexture.setFilter(TextureFilter.Linear,  TextureFilter.Linear);
        jumperSprite = new Sprite(overallTexture, 0, 0, 32, 37);
        spriteBatch = new SpriteBatch();
        BodyDef jumperBodyDef = new BodyDef();
        jumperBodyDef.type = BodyDef.BodyType.DynamicBody;
        jumperBodyDef.position.set(1.0f, 3.0f);

        jumper = world.createBody(jumperBodyDef);
        PolygonShape jumperShape = new PolygonShape();
        jumperShape.setAsBox(jumperSprite.getWidth() / (2 * PIXELS_PER_METER),
        jumperSprite.getHeight() / (2 * PIXELS_PER_METER));
        jumper.setFixedRotation(true);

        FixtureDef jumperFixtureDef = new FixtureDef();
        jumperFixtureDef.shape = jumperShape;
        jumperFixtureDef.density = 1.0f;
        jumperFixtureDef.friction = 5.0f;

        jumper.createFixture(jumperFixtureDef);
        jumperShape.dispose();


    }

现在会发生什么:当角色到达某个 Y 坐标时,它会将他重置在起点。错误在于,每当发生这种情况时,它重置他的 Y 坐标,他的“形状”仍然像一个盒子一样在那里。所以每当你再次落到那个 Y 坐标时,你不会因为你落在他的“形状”上而被重置。有任何想法吗?

4

1 回答 1

0

AndEngine 有一个叫做物理连接器的东西,因为 AndEngine 使用 LibGDX 的 Box2D 实现,可能 LibGDX 中也存在 registerPhysicsConnector() 方法。

于 2012-06-10T20:30:40.580 回答