我正在创建一个基于瓷砖的游戏,它使用2组布尔数组来确定需要绘制每堵墙的位置,从而绘制迷宫。
目前我已经将其全部设置好了,只绘制了5x5个迷宫区域(整个迷宫大小为30x30)。然而,当我移动角色时,整个屏幕会跳动,这是因为下一部分迷宫正在被绘制,以保持5x5的纵横比。我尝试了各种不同的方法来使其流畅运行,但似乎无法做到。
请问是否有人可以提供建议或指向一些链接/示例,以便我可以使迷宫和角色的移动都平稳地进行。以下是当前绘制迷宫的主要for循环的基本代码,以及它引用的两个布尔数组,用于绘制墙壁。
我愿意完全重写那段代码,如果能使其流畅绘制。然而,我尝试了几种不同的变化,都不能使其平滑,总是有跳跃。我也试图使用canvas translate来实现,先绘制整个迷宫,然后缩放它,只显示5 x 5,然后简单地使用translate沿着移动缩放的部分,同时保持角色在屏幕中心,从而实现平滑移动。但是,我无法使translate平稳移动。
目前我已经将其全部设置好了,只绘制了5x5个迷宫区域(整个迷宫大小为30x30)。然而,当我移动角色时,整个屏幕会跳动,这是因为下一部分迷宫正在被绘制,以保持5x5的纵横比。我尝试了各种不同的方法来使其流畅运行,但似乎无法做到。
请问是否有人可以提供建议或指向一些链接/示例,以便我可以使迷宫和角色的移动都平稳地进行。以下是当前绘制迷宫的主要for循环的基本代码,以及它引用的两个布尔数组,用于绘制墙壁。
// THE CODE TO DRAW THE MAZE AND ITS 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;
// Draw Verticle line (y axis)
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);
}
// Draws Horizontal lines (x axis)
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);
}
}
}
// THE 2 BOOLEAN ARRAYS THE FORLOOP REFERENCES
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 }
};
我愿意完全重写那段代码,如果能使其流畅绘制。然而,我尝试了几种不同的变化,都不能使其平滑,总是有跳跃。我也试图使用canvas translate来实现,先绘制整个迷宫,然后缩放它,只显示5 x 5,然后简单地使用translate沿着移动缩放的部分,同时保持角色在屏幕中心,从而实现平滑移动。但是,我无法使translate平稳移动。