2017-02-09 63 views
1

我現在暫時使用box2ddebugrenderer將身體呈現到世界中,但我無法看到運行時在世界中創建的物體的單色輪廓。無法看到Box2DdebugRenderer的身體輪廓

這是我的遊戲屏幕的代碼:

public class GameScreen implements Screen { 

static final int VIEWPORT_WIDTH = 20; 
static final int VIEWPORT_HEIGHT = 13; 

World world; 
Body ground; 

final float TIME_STEP = 1/300f; 
float accumulator = 0f; 

OrthographicCamera camera; 
private Box2DDebugRenderer renderer; 

@Override 
public void render(float delta) { 
    //Clear the screen 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 

    renderer.render(world, camera.combined); 

    accumulator += delta; 

    while (accumulator >= delta) { 
     world.step(TIME_STEP, 6, 2); 
     accumulator -= TIME_STEP; 
    } 
} 



@Override 
public void show() { 
    world = createWorld(); 
    ground = createGround(world); 
    renderer = new Box2DDebugRenderer(); 

    camera = new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); 
    camera.position.set(camera.viewportWidth/2, camera.viewportHeight/2, 0f); 
    camera.update(); 

} 

public World createWorld() { 
    return new World(Constants.WORLD_GRAVITY, true); 
} 

public Body createGround(World world) { 
    BodyDef bodyDef = new BodyDef(); 
    bodyDef.position.set(new Vector2(Constants.GROUND_X, Constants.GROUND_Y)); 
    Body body = world.createBody(bodyDef); 
    PolygonShape shape = new PolygonShape(); 
    shape.setAsBox(Constants.GROUND_WIDTH/2, Constants.GROUND_HEIGHT/2); 
    body.createFixture(shape, Constants.GROUND_DENSITY); 
    shape.dispose(); 
    return body; 
} 
}  

回答

0

需要BodyDef定義物理身體的體形

BodyDef bodyDef=new BodyDef(); 
bodyDef.BodyType= BodyType.STATIC; 

不同的恆定的值要適當,使身體趴在相機內像你一樣的視口
Constants.GROUND_X,
Constants.GROUND_Y,
Constants.GROUND_WIDTH,
Constants.GROUND_HEIGHT

創建小體和檢查,身體輪廓是否可見。
之後,仍然如果你在屏幕上沒有任何東西使用SpriteBatch繪製簡單的雪碧。

另外一個條件
可能是您在您的Child Game類中重寫了Game的渲染方法,而不是調用父級渲染方法。