i started trying to develop a tower defence game for android. Unfortunately i don't have so much experience with java. I already got a map you can scroll and cells that can contain towers (drawn as circles). But when scrolling over the map with some towers there is a delay between towers an background and the towers seem to move. To scroll over the background i show a part of a bitmap that is resized depending on the Scrolloffset.
- Code: Select all
public void onDraw(Canvas canvas) {
Bitmap resizedBackground = Bitmap.createBitmap(background,XOffset, YOffset, getWidth(), getHeight());
canvas.drawBitmap(resizedBackground, 0, 0, null);
//draw grid
int actViewRow = 0;
int actViewCell;
int X;
int Y;
for(int i = startRow; i < maxRow; i++){
actViewCell = 0;
Row = MapCells.get(i);
//calculate Coordinates on current View
Y = actViewRow * CellSize - YScrollOffset;
for(int j = startCell; j<maxCell ;j++){
X = actViewCell * CellSize - XScrollOffset;
Row.get(j).draw(canvas, Paint, X, Y, showGrid);
actViewCell++;
}
actViewRow++;
}
My Questions are:
1. is there a way to draw the background and the towers at the same time to avoid the delay
or 2. is there a delay because of resizing the image all the time, how could i do better
3. would the app perform better if i just draw an bitmap for each cell of the map and change the bitmap if a tower is set on the cell
Thanks for your help.
PS. I hope you can understand me. I did not write any line of javacode for the last 2 years and any line of english sentences for 4 years



