首页 > 解决方案 > 颜色渲染不正确

问题描述

这源于一个问题,许多人从您可以在此处找到的 vanZeben 的游戏引擎教程中得到。问题是 vanZeben 使用的渲染函数。这是非常尴尬和限制。我需要删除它并用呈现精灵表上颜色的代码替换它。

编辑:是整个项目源代码的链接。

我最接近的是从 int col 初始化中删除颜色 >> 。它仍然会删除所有颜色,除了我在完成教程后添加的瓷砖。

//I know the problem comes from this section of code.               

int col = (color >> (sheet.pixels[xSheet + ySheet * sheet.width + tileOffset] * 8) & 255);

            if (col < 255)
            {
                for(int yScale = 0; yScale < scale; yScale++)
                {
                    if (yPixel + yScale < 0 || yPixel + yScale >= height) continue;

                    for(int xScale = 0; xScale < scale; xScale++)
                    {
                        if (xPixel + xScale < 0 || xPixel + xScale >= width) continue;
                        pixels[(xPixel + xScale) + (yPixel + yScale) * width] = col;
                    }
                }
            }

我只需要 col 等于精灵表上像素的颜色。

标签: javacolors

解决方案


推荐阅读