I am trying to draw a grid for my "world" that may or may not extend beyond the screen. What I would like to do right now is draw the entire world (which is relatively small) and then use the orthographic camera to translate the view to where the player is inside the "world." Currently I'm just trying to translate the "world" by 100 on the x and y axis to test. What am I doing wrong? Can I use the Shaperenderer with the OrthographicCamera?
public class WorldRenderer implements Disposable{
private static WorldRenderer worldRenderer;
private Color gridLineColor = Color.LIGHT_GRAY;
private OrthographicCamera camera;
private int worldX;
private int worldY;
public WorldRenderer(WorldController worldController) {
init();
}
public void init() {
worldRenderer = this;
camera = new OrthographicCamera();
worldX = 0;
worldY = 0;
}
public void render() {
//Set the background color to white.
Gdx.gl.glClearColor(255, 255, 255, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
renderBackground();
}
public void renderBackground() {
ShapeRenderer renderer = new ShapeRenderer();
//Draw vertical lines.
for(int i=0;i<=Constants.WORLD_WIDTH * Constants.GRID_WIDTH;i+=Constants.GRID_WIDTH) {
renderer.begin(ShapeType.Line);
renderer.setColor(gridLineColor);
renderer.line(i, 0, i, Constants.WINDOW_HEIGHT);
renderer.end();
}
//Draw horizontal lines.
for(int i=0;i<=Constants.WORLD_HEIGHT * Constants.GRID_HEIGHT;i+=Constants.GRID_HEIGHT) {
renderer.begin(ShapeType.Line);
renderer.setColor(gridLineColor);
renderer.line(0, i, Constants.WINDOW_WIDTH, i);
renderer.end();
}
camera.translate(100, 100);
}
}