所以我有这个函数可以将图像中的图块渲染到像素数组。我正在尝试制作一个新功能来将图像从 7*7 放大到 14*14
每个瓦片是8*8
- xp = X 位置
- yp = Y 位置
- 瓷砖=瓷砖
- 位置颜色 = 像素颜色
我相当确定这将是一项简单的任务,因为我认为我只需要扩展数组并共享位来填补空白。
如果您需要更多信息或需要我进一步简化代码,请告诉我。
public void scaledRender(int xp, int yp, int tile, int colors) {
xp -= xOffset;
yp -= yOffset;
int xTile = tile % 32;
int yTile = tile / 32;
int toffs = xTile * 8 + yTile * 8 * sheet.width;
int ys, xs;
for (int y = 0; y < 8; y++) {
ys = y;
if (y + yp < 0 || y + yp >= h)
continue;
for (int x = 0; x < 8; x++) {
if (x + xp < 0 || x + xp >= w)
continue;
xs = x;
int col = (colors >> (sheet.pixels[xs + ys * sheet.width + toffs] * 8)) & 255;
if (col < 255)
pixels[((x + xp) + (y + yp) * w)] = Screen.colors[col] | 0xff000000;
}
}
}
编辑:
这行得通。感谢 GamerJosh。我不知道这是否是最有效的方法,但它确实有效!
public void scaledRender(int xp, int yp, int tile, int colors) {
xp -= xOffset;
yp -= yOffset;
int xTile = tile % 32;
int yTile = tile / 32;
int toffs = xTile * 8 + yTile * 8 * sheet.width;
int ys, xs;
for (int y = 0; y < 8; y++) {
ys = y;
if (y + yp < 0 || y + yp >= h)
continue;
for (int x = 0; x < 8; x++) {
if (x + xp < 0 || x + xp >= w)
continue;
xs = x;
int col = (colors >> (sheet.pixels[xs + ys * sheet.width + toffs] * 8)
if (col < 255) {
pixels[((x + xp)*2 ) + ((y + yp)*2 ) * w ] = Screen.colors[col] | 0xff000000;
pixels[((x + xp)*2+1) + ((y + yp)*2 ) * w ] = Screen.colors[col] | 0xff000000;
pixels[((x + xp)*2 ) + ((y + yp)*2+1) * w ] = Screen.colors[col] | 0xff000000;
pixels[((x + xp)*2+1) + ((y + yp)*2+1) * w ] = Screen.colors[col] | 0xff000000;
}
}
}
}