首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >渲染8种单色精灵

渲染8种单色精灵
EN

Stack Overflow用户
提问于 2016-02-21 00:48:19
回答 1查看 70关注 0票数 0

我想要一个16x16单色精灵显示在我的屏幕上。雪碧有8种不同的颜色,对应于8种不同的颜色。每种颜色都可以有自己的颜色,但我想把它限制在8,所以我不想要FF00FF,我希望它像707。

我在github上有个项目

到目前为止,我得到的情况如下:

这就是我创建所有可能的颜色的地方:

代码语言:javascript
复制
int[] colours = new int[8 * 8 * 8];
int index = 0;
for(int r = 0; r < 8; r++) {
    for(int g = 0; g < 8; g++) {
        for(int b = 0; b < 8; b++) {
            int rr = r * 255 / 7;
            int gg = g * 255 / 7;
            int bb = b * 255 / 7;

            colours[index++] = rr << 16 | gg << 8 | bb;
        }
    }
}

这就是我想要调用包含所有颜色信息的长int的地方:

代码语言:javascript
复制
public class Colours {
    public static int get(int c1, int c2, int c3, int c4, int c5, int c6, int c7, int c8) {
    //bit shifting with 56 on an integer removes data
    return((get(c8) << 28) + (get(c7) << 24) + (get(c6) << 20) + (get(c5) >> 16) +
    (get(c4) << 12) + (get(c3) << 8) + (get(c2) << 4) + (get(c1)));
}

private static int get(int colour) {
    if(colour < 0) {
        return 255;
    }
    int r = colour / 100 % 10;
    int g = colour / 10 % 10;
    int b = colour % 10;
    return r * 64 + g * 8 + b;
    }
}

这是屏幕呈现的地方:

代码语言:javascript
复制
public void render(int xPos, int yPos, int tile, int colour) {
    xPos -= xOffset;
    yPos -= yOffset;

    int xTile = tile % 32;
    int yTile = tile / 32;
    int tileOffset = (xTile << 4) + (yTile << 4) * sheet.width;

    for (int y = 0; y < 16; y++) {
        if (y + yPos < 0 || y + yPos >= height) {
            continue;
        }
        int ySheet = y;
        for (int x = 0; x < 16; x++) {
            if (x + xPos < 0 || x + xPos >= width) {
                continue;
            }
            int xSheet = x;
            int col = (colour >> (sheet.pixels[xSheet + ySheet * sheet.width + tileOffset] * 16)) & 255;
            if (col < 255) {
                pixels[(x + xPos) + (y + yPos) * width] = col;
            }
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-29 18:25:51

我通过返回一个整数数组来修正它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35530958

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档