What i need help with is how can i get a chunk of a large 2d char array and update it so i am only drawing enough tiles to cover the screen?
Currently, i load all the chars from a text file and store them in an array. I then create a smaller array:char[][] toDraw = new char[height][width]
which gets the first height*width area of chars from the larger array like this:
public void filterMap() {
for(int i = 0; i < height; i++) {
for(int j = 0; j < width; j++) {
toDraw[i][j] = MapLoader.mapData[i][j];
}
}
}
I then draw the map using this drawMap method:
public void drawMap(Canvas canvas) {
for(int i = 0; i < height; i++) {
for(int j = 0; j < width; j++) {
if(getBitmap(toDraw[i][j]) != null) {
canvas.drawBitmap(getBitmap(toDraw[i][j]), x + (j*tileSize), y + (i*tileSize), null);
}
}
}
}
note the int x and y are what i increment to move the map, getBitmap(char c) returns a Bitmap from a char, MapLoader.mapData is the 2d array that the text file loads into.
I have tried a few ways of using an offset in the toDraw arrays index to scroll the data relevant to the x,y location but they have been buggy/failed.
So, does anybody have a link to how things like this can be done (I have tried but have found none that help) or could someone with experience in 2d games please tell/show me how this should be done.
Currently my code will get a area from the larger array and draw it to the screen, the only problem is updating the data in the toDraw array. thanks.
The game is made for android but is not included in tags because i dont feel it is relevant to the problem