2013-08-31 36 views
4

我有一個libgdx遊戲與Box2d和Box2d燈的作品。Libgdx讓燈忽略機構

我的問題是我如何讓Bodys/Bodydefs忽略來自Box2d Light的光源而不投射陰影?

謝謝。

PolygonShape groundBox = new PolygonShape(); 
    groundBox.setAsBox(2f, 2f); 

    FixtureDef gridBox = new FixtureDef(); 
    gridBox.shape = groundBox; 
    gridBox.density = 1.0f; 

    gridBox.filter.groupIndex = GRID_GROUP; 
    gridBox.filter.categoryBits = GRID_CAT; 
    gridBox.filter.maskBits = GRID_MASK; 

    bodyDefs[i][j] = new BodyDef();  
    bodyDefs[i][j].position.set(j*factor + factor, i*factor + factor); 
    bodyDefs[i][j].fixedRotation = true; 
    bodyDefs[i][j].type = BodyDef.BodyType.DynamicBody; 

    bodies[i][j] = world.createBody(bodyDefs[i][j]); 
    bodies[i][j].createFixture(gridBox); 

    handler = new RayHandler(world); 
    handler.setCombinedMatrix(camera.combined); 
    Filter filter = new Filter(); 
    filter.groupIndex = GRID_GROUP; // GRID_GROUP = 1 
    filter.categoryBits = GRID_CAT; // GRID_CAT = 0x0001; 
    filter.maskBits = GRID_MASK; // GRID_MASK = 1; 

    new PointLight(handler, 1000, Color.RED, 2000, 0, height); 

    PointLight.setContactFilter(filter); 
+0

你有管理這個工作?我有同樣的問題。你可以分享你的獨奏或暗示嗎? – Veljko

回答

9

可以使用下面的方法:

cone.setContactFilter(categoryBits對groupIndexmaskBits);

其中圓錐體是的對象ConeLight。現在這個燈會忽略具有指定的categoryBits,groupIndex和maskBits的機構。

您可以設置通過人體的在 夾具categoryBits,對groupIndex和maskBits下述方式

fixture.filter.categoryBits =你的價值;

(categoryBits:碰撞類別位通常你只會設置一個位)

fixture.filter.groupIndex =你的價值;

(對groupIndex:碰撞組允許一組特定對象來從未碰撞(負)或總是碰撞(正)零表示 沒有碰撞組非零羣濾波總是獲勝對的屏蔽位。)

fixture.filter.maskBits =你的價值

(maskBits:該碰撞掩碼位,這說明這種形狀會接受碰撞的類別)

如果你希望一些機構無視所有的燈那麼你可以使用下面 .setContactFilter(categoryBits,對groupIndex,maskBits)

+0

我認爲這是正確的方法,但我遇到問題實施它。我已經更新了我的問題以幫助清除空氣。 – Oonej

+0

沒關係我想通了:) – Oonej

0

相信接觸過濾器只能被應用到使用Box2D的燈全燈。我嘗試使用aug13引用的setContactFilter方法來設置它們,但這是一種從Light繼承的靜態方法,無法從對象調用。我不知道它是否可以在過去的某個時候。

從文檔:

public static void setContactFilter(short categoryBits, 
        short groupIndex, 
        short maskBits) 

創建所有的燈新的聯繫人過濾器給予參數