I have trouble to render a 2d blocky map.
Here how the 2d map array created :
map = new Block[w * h];
The block class contains 2 variables - size( H:100px, W:100px), and image texture.
Ok, so how should I render it? I mean lets say the player is walking in the map, how should i make the map move / scroll effect.
I tried to loop through the map and render it but without any luck. because i need somehow to slice the block when i render it and i dont have any idea how to do that.
I really need help and it will be very appreciated!
This:
map = new Block[w * h];
Should be a 2d array:
map = new Block[w][h];
Or I am misunderstanding?
Ok, so how should I render it?
If each block has an image texture then just loop through it, something like this:
for(int i=0; i<w; i++){
for(int j=0; j<h; j++){
Block b = map[i][j];
spritebatcher.draw(b.texture, i*b.W, j*b.H);
}
}
how should i make the map move / scroll effect?
Technically the map won't scroll. You move your player and the camera will follow him/her.
camera.position.set(player.position.x, player.position.y, 0);
i need somehow to slice the block when i render it and i dont have any idea how to do that.
I'm afraid I don't understand this particular issue.