0
爲什麼玩家不與地面碰撞?我使用過濾器錯了嗎? 我將所有常量存儲在一個名爲Constants的類中。這裏是我使用的代碼:如何正確使用過濾器?
for (MapObject object : map.getLayers().get(2).getObjects().getByType(RectangleMapObject.class)) {
Rectangle rect = ((RectangleMapObject) object).getRectangle();
bDef.type = BodyDef.BodyType.StaticBody;
bDef.position.set((rect.getX() + rect.getWidth()/2)
/Constants.PPM, (rect.getY() + rect.getHeight()/2)
/Constants.PPM);
body = world.createBody(bDef);
shape.setAsBox(rect.getWidth()/2/Constants.PPM,
rect.getHeight()/2/Constants.PPM);
fDef.shape = shape;
body.createFixture(fDef);
fDef.filter.categoryBits = Constants.BRICK_BIT;
fDef.filter.maskBits = Constants.PLAYER1_BIT;
}
這裏是我如何定義我的播放器。我如果那是一個傾倒的問題,但我在LibGDX一個完整的新手...
public void defineMainPlayer1() {
BodyDef bDef = new BodyDef();
bDef.position.set(128/Constants.PPM, 256/Constants.PPM);
bDef.type = BodyDef.BodyType.DynamicBody;
b2body = world.createBody(bDef);
PolygonShape shape = new PolygonShape();
shape.setAsBox(42/2/Constants.PPM, 94/2/Constants.PPM);
FixtureDef fDef = new FixtureDef();
fDef.shape = shape;
fDef.filter.categoryBits = Constants.PLAYER1_BIT; // Setting the filter
// for my Player
fDef.filter.maskBits = Constants.BRICK_BIT;
b2body.createFixture(fDef).setUserData(this);
EdgeShape head = new EdgeShape();
head.set(new Vector2(-30/Constants.PPM, 49/Constants.PPM),
new Vector2(30/Constants.PPM, 49/Constants.PPM));
fDef.shape = head;
fDef.isSensor = true;
b2body.createFixture(fDef).setUserData("head");
}
你可以顯示你的Constants.BRICK_BIT和Constants.BRICK_BIT的定義嗎? – Aleris