Hello
I am currently working in Libgdx and making a 3D top down game
I have made 1 chunk, however I am not sure how to handle multiple chunks
I want the system to work like this, I have 9 meshes (top left, top,top right,etc etc) I only want 9 chunks in the game at one given time, every time the player moves out of the chunk range it will generate and allocate a new chunk and deallocate a not visible chunk meaning It will only need 9 meshes (9 draw calls)
I am just not sure how to handle this… can someone explain the ways for me, there is no up or down its just like a 2D game I am only using X and Z
This is the world code
package com.hawk.green.world;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.utils.Disposable;
import com.hawk.green.Art;
public class World implements Disposable {
static final short MAX_CHUNKS = 9;
private Mesh[] chunkMeshes = new Mesh[MAX_CHUNKS];
private Chunk[] chunks = new Chunk[MAX_CHUNKS];
private Camera camera;
private ShaderProgram shader;
public World(Camera camera) {
this.camera = camera;
shader = Art.getInstance().getShaderProgram();
for(int i = 0;i < MAX_CHUNKS;++i){
chunkMeshes[i] = ChunkMeshBuilder.createEmptyChunkMesh();
}
}
public void render() {
shader.begin();
shader.setUniformMatrix("u_projTrans", camera.combined);
for(int i = 0;i < MAX_CHUNKS;++i)
chunkMeshes[i].render(Art.getInstance().getShaderProgram(), GL20.GL_TRIANGLES);
shader.end();
}
@Override
public void dispose() {
for(int i = 0;i < MAX_CHUNKS;++i)
chunkMeshes[i].dispose();
}
}
This is my chunk code
public class Chunk {
public final static int CHUNK_SIZE = 32;
public final static int WORLD_HEIGHT = 2;
private short[][][] blocks = new short[CHUNK_SIZE][WORLD_HEIGHT][CHUNK_SIZE];
private Vector2 position;
public Chunk(float x,float z) {
position = new Vector2(x, z);
}
void reset() {
for (int x = 0; x < CHUNK_SIZE; ++x) {
for (int y = 0; y < WORLD_HEIGHT; ++y) {
for (int z = 0; z < CHUNK_SIZE; ++z) {
blocks[x][y][z] = 0;
}
}
}
}
public Vector2 getPosition() {
return position;
}
}