我目前有一个迷宫游戏,它绘制了一个5x5的正方形(占据屏幕宽度并平均分割)。然后,对于这些盒子中的每一个,使用x和y坐标,我使用drawRect来绘制有颜色的背景。
我现在遇到的问题是,我需要在同一位置绘制一张图片,因此替换当前的纯色背景填充。
以下是我目前使用的drawRect代码(几个示例):
// these are all the variation of drawRect that I use
canvas.drawRect(x, y, (x + totalCellWidth), (y + totalCellHeight), green);
canvas.drawRect(x + 1, y, (x + totalCellWidth), (y + totalCellHeight), green);
canvas.drawRect(x, y + 1, (x + totalCellWidth), (y + totalCellHeight), green);
接下来,我还需要在画布中为所有其他正方形实现一个背景图像。这个背景将在其上方绘制简单的1像素黑线,当前代码是在灰色背景上绘制。
background = new Paint();
background.setColor(bgColor);
canvas.drawRect(0, 0, width, height, background);
请问是否有可能实现这一点?如果可以,我应该如何做到在尽量减少内存使用的同时只使用1个图像并使其扩大和缩小以填充相关方形空间(这在所有不同的屏幕尺寸上都会有所不同,因为它将整个屏幕宽度均分)。