2017-02-09 1 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=new BodyDef(); 
bodyDef.BodyType= BodyType.STATIC; 

다른 상수의 값은 적절해야 BodyDef 물리학 본체의 타입의 몸매를 정의 할 필요가 있으므로 카메라 내에서 그 몸 거짓말 같은 뷰포트
Constants.GROUND_X,
Constants.GROUND_Y,
Constants.GROUND_WIDTH, Constants.GROUND_HEIGHT

작은 몸체를 만들고 확인하면 몸체가 보입니다.
그 후에도 화면에 아무것도 표시되지 않으면 SpriteBatch를 사용하여 간단한 Sprite를 그립니다.

하나 더 조건
하위 게임 클래스에서 게임의 렌더링 방법을 재정의하고 상위 렌더링 방법을 호출하지 않을 수 있습니다.