Bug muito estranho do LibGDX - objetos desaparecem
Quando eu estava criando meu primeiro criador de mapas lado a lado emlibGDX
, Notei um bug muito estranho. Estou criando grade de objetos como este:
private static final int GRID_WIDTH=2400;
private static final int GRID_HEIGHT=2400;
private static final int CELL_SIZE=60;
assim você pode ver que existem 2400 / 60x2400 / 60 objetos ou células. Estou criando meu mapa assim:
private void createMap(){
cells = new Cell[GRID_WIDTH/CELL_SIZE][GRID_HEIGHT/CELL_SIZE];
for(int i=0;i<GRID_WIDTH/CELL_SIZE;++i){
for(int j=0;j<GRID_HEIGHT/CELL_SIZE;++j){
cells[i][j]=new Cell(textures[0],i*CELL_SIZE,j*CELL_SIZE);
}
}
}
Também tenho coordenadas para minha depuração na tela, para que eu saiba onde elas começaram a desaparecer. A coordenada Y está ok, existem de 0 a 2400, mas no X elas começaram a desaparecer às 1500. Quando começo a desenhar alguma textura, todas as colunas ficam visíveis para essa textura, por exemplo (quando começo a escrever textura em x = 2100 todas as colunas desaparecidas ficarão visíveis para 2100) e quando eu excluir essa textura, todas as colunas desaparecerão novamente para 1500. Portanto, os objetos estão lá, mas não são visíveis. É tão chato que alguém sabe sobre esse bug?
Como você pode ver, as coordenadas estão no canto inferior esquerdo, no início:
e é aí que vou acrescentar alguma textura
[Editado] Código com a câmera:
private float x=GRID_WIDTH/2,y=GRID_HEIGHT/2;
@Override
public void render(float delta) {
batch = new SpriteBatch();
camera=new OrthographicCamera(CAM_WIDTH,CAM_HEIGHT);
viewPos = new Vector3();
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
viewPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
camera.unproject(viewPos);
batch.begin();
if(Gdx.input.isKeyPressed(Input.Keys.RIGHT) || Gdx.input.isKeyPressed(Input.Keys.D))
x+=SPEED*Gdx.graphics.getDeltaTime();
if(Gdx.input.isKeyPressed(Input.Keys.LEFT) || Gdx.input.isKeyPressed(Input.Keys.A))
x-=SPEED*Gdx.graphics.getDeltaTime();
if(Gdx.input.isKeyPressed(Input.Keys.UP) || Gdx.input.isKeyPressed(Input.Keys.W))
y+=SPEED*Gdx.graphics.getDeltaTime();
if(Gdx.input.isKeyPressed(Input.Keys.DOWN) || Gdx.input.isKeyPressed(Input.Keys.S))
y-=SPEED*Gdx.graphics.getDeltaTime();
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
camera.position.set(x,y,0);
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.end();
}