Hirdetés

Új hozzászólás Aktív témák

  • trisztan94

    őstag

    Sziasztok!

    libgdx-el és box2d-val kapcsolatban lenne egy kérdésem.

    Hogy tudok egy Body-nak adni egy saját "nevet"?

    Jelenleg így van beállítva egy body nekem:

    groundDef = new BodyDef();
    groundDef.type = BodyType.StaticBody;
    groundDef.position.set(new Vector2(0, 0));

    groundBody = world.createBody(groundDef);

    groundShape = new PolygonShape();
    groundShape.setAsBox(800, 10);

    groundFixture = new FixtureDef();
    groundFixture.shape = groundShape;
    groundFixture.density = 1f;
    groundFixture.friction = 1f;
    groundFixture.restitution = 0f;
    groundFixture.filter.categoryBits = CATEGORY_GROUND;
    groundFixture.filter.maskBits = MASK_GROUND;


    groundBody.createFixture(groundFixture);
    groundBody.setUserData("ground");

    A legutolsó sorban hozzáadtam a userData-hoz a "ground" nevet, de mintha nem is lenne ott.

    Ilyen a contact listenerem:

    @Override
    public void beginContact(Contact contact) {
    Fixture fixtureA = contact.getFixtureA();
    Fixture fixtureB = contact.getFixtureB();
    Gdx.app.log("beginContact", "between " + fixtureA.toString() + " and " + fixtureB.toString());
    }
    ...

    Amikor két body ütközik, akkor kiír egy baromi hosszú kódot arra, hogy melyik két body ütközött:

    beginContact: between com.badlogic.gdx.physics.box2d.Fixture@69dbb4d1 and com.badlogic.gdx.physics.box2d.Fixture@573c3ba2

    :F

Új hozzászólás Aktív témák