2016-10-12 5 views
0

플레이어가지면과 충돌하지 않는 이유는 무엇입니까? 필터를 잘못 사용 했습니까? 모든 상수를 상수라는 클래스에 저장합니다. 다음은 내가 사용하는 코드입니다.필터를 올바르게 사용하려면 어떻게해야합니까?

내 플레이어 정의 방법은 다음과 같습니다.

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"); 

} 
+0

Constants.BRICK_BIT 및 Constants.BRICK_BIT의 정의를 표시 할 수 있습니까? – Aleris

답변

0

당신은 내가 쓴

fDef.filter.categoryBits = Constants.BRICK_BIT; 
fDef.filter.maskBits = Constants.PLAYER1_BIT; 

body.createFixture(fDef); 
0

body.createFixture(fDef); 

fDef.filter.categoryBits = Constants.BRICK_BIT; 
fDef.filter.maskBits = Constants.PLAYER1_BIT; 

의 순서를 변경해야 ... 덤프 질문을 먹으 렴 경우에 나는,하지만 난 LibGDX에서 완전한 초보자입니다 아래 예는 명확한 설명과 아이디어를 제공합니다.

short CAT_PLAYER = 0x001; 
short CAT_ENEMY = 0x002; 
short CAT_SENSOR = 0x004; 
short CAT_WALL = 0x008; 

short MASK_PLAYER = ~CAT_PLAYER; // cannot collide to a player 
short MASK_ENEMY = ~CAT_ENEMY; // cannot collide to a enemy 
short MASK_SENSOR = CAT_PLAYER; // can only collide to a player 
short MASK_WALL = -1; // can collide to all 

그리고 플레이어의 조명기에 대한 간단한 필터. 즉, 플레이어는 자신을 제외한 모든 플레이어와 충돌 할 수 있습니다.

filter.categoryBits = CAT_PLAYER; 
filter.maskBits = MASK_PLAYER; 
관련 문제