如何摆脱不需要的形状

时间:2012-06-10 20:07:16

标签: android 2d

这是我的'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;

这是我的'public void render()'

的一部分
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坐标时,你就不会因为你的“形状”而被重置。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

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