2017-02-09 55 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的渲染方法,而不是调用父级渲染方法。