I am currently creating a tile-based game that essentially draws a maze using 2 sets of logical arrays to determine where each wall needs to be drawn.
I have everything I need, with only 5 × 5 sections of the maze (the total size of the maze is 30 x 30). However, the problem I am facing is that when I move the character, the whole screen jumps, this is due to the fact that the next section of the maze is drawn to maintain an aspect ratio of 5 x 5. I tried different things to try to do this the run is smooth, but it seems it just can't do it.
Can someone advise or direct me to some links / examples so that I can make the maze and character movements all go smoothly. Below is the basic code regarding the main loop, which currently draws a maze and 2 Boolean arrays, which it refers to to draw walls.
for(int i = 0; i < 5; i++)
{
for(int j = 0; j < 5; j++)
{
float x = j * totalCellWidth;
float y = i * totalCellHeight;
if(currentY != 0)
indexY = i + currentY - 1;
else
indexY = i + currentY;
if(currentX != 0)
indexX = j + currentX - 1;
else
indexX = j + currentX;
if (indexY < vLength && indexX < vLines[indexY].length && vLines[indexY][indexX])
{
RectOuterBackground.set((int)x + (int)cellWidth, (int)y, (int)x + (int)cellWidth + 15, (int)y + (int)cellHeight + 15);
canvas.drawBitmap(walls, null, RectOuterBackground, null);
}
if (indexY < hLength && indexX < hLines[indexY].length && hLines[indexY][indexX])
{
RectOuterBackground.set((int)x, (int)y + (int)cellHeight,(int)x + (int)cellWidth + 15,(int)y + (int)cellHeight + 15);
canvas.drawBitmap(walls, null, RectOuterBackground, null);
}
}
}
boolean[][] vLines = new boolean[][]{
{true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true },
{true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true },
{true ,true ,true ,false,false,false,true ,false,false,true ,true },
{true ,true ,true ,false,false,true ,false,true ,true ,true ,true },
{true ,true ,false,true ,false,false,true ,false,false,true ,true },
{true ,true ,false,true ,true ,false,false,false,true ,true ,true },
{true ,true ,true ,false,false,false,true ,true ,false,true ,true },
{true ,true ,false,true ,false,false,true ,false,false,true ,true },
{true ,true ,false,true ,true ,true ,true ,true ,false,true ,true },
{true ,true ,false,false,false,true ,false,false,false,true ,true },
{true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true },
{true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true }
};
boolean[][] hLines = new boolean[][]{
{true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true },
{true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true },
{true ,true ,false,false,true ,true ,false,false,true ,false,true ,true },
{true ,true ,false,false,true ,true ,false,true ,false,false,true ,true },
{true ,true ,true ,true ,false,true ,true ,false,true ,true ,true ,true },
{true ,true ,false,false,true ,false,true ,true ,false,false,true ,true },
{true ,true ,false,true ,true ,true ,true ,false,true ,true ,true ,true },
{true ,true ,true ,false,false,true ,false,false,true ,false,true ,true },
{true ,true ,false,true ,false,false,false,true ,false,true ,true ,true },
{true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true },
{true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true }
};
I am ready to completely rewrite this section of the code, if I can make it draw smoothly, however, after trying several different variations, it cannot be smooth, I always have a jump.
I also tried to get it to work with the canvas translation by plotting the whoel maze, then scale it so that only 5 x 5 is displayed, and then just move the scaled section using the translation, keeping the character in the center of the screen for smooth movement. However, I simply could not get the translation to move smoothly.