Spr*_*bua 8 java textures colors libgdx
在一个游戏中,用TextureAtlas我制作的TextureRegion,其中我存储Animation了我Player的所有s Player.在Player默认情况下,具有蓝色T恤(例如).
现在我希望能够有一个以上Player,每个人都Player应该有另一种T恤颜色.
所以基本上我想用蓝色代替红色代替第二代PixMap,绿色代替第三代TextureAtlas,依此类推.
我相信我能做到这一点TextureRegion,但我不会失去优势TextureAtlas吗?
还有其他可能吗?或者我需要有每一个"彩色版"作为Texture在TextureAtlas?
另一个小问题:
使用Gimp(可能还有一些其他程序),您可以使用".gif"文件的颜色索引.通过为文件中的每种颜色保存索引,然后使用此索引来描述像素,
这会减小所有TextureAtlass 的大小.因此,对于每个红色像素,您将拥有"1"而不是"#FF0000",并且文件中的某处有"1 =#FF0000".
如果然后打包带有颜色索引的".gif"文件TextureRegion,那么索引会丢失并恢复默认的RGB颜色或会产生问题吗?
非常感谢!
我在使用相同纹理生成具有随机颜色的武器时遇到了同样的问题。
所以我写了这个。
基本上我制作了你想要编辑的纹理的像素图。
然后迭代所有像素,在迭代时我检查某些颜色,这些颜色是纹理的特定部分。(我建议使用不同的灰色阴影,因为 RGB 是相同的)
然后,当它位于需要更改颜色的像素上时,我使用颜色选择器方法获取这些像素组的颜色,该方法基本上是随机的,可以获取颜色来自预制颜色数组,
然后将该特定像素更改为新颜色。
/**
* Requires a asset's textureName, and requires gray scale colors of the
* parts
*
* @param texturename
* @param colorBlade
* @param colorEdge
* @param colorAffinity
* @param colorGrip
* @return
*/
private static Texture genTexture(String texturename, int colorBlade,
int colorEdge, int colorAffinity, int colorGrip, int colorExtra) {
Texture tex = Game.res.getTexture(texturename);
TextureData textureData = tex.getTextureData();
textureData.prepare();
Color tintBlade = chooseColor(mainColors);
Color tintEdge = new Color(tintBlade.r + 0.1f, tintBlade.g + 0.1f,
tintBlade.b + 0.1f, 1);
Color tintAffinity = chooseColor(affinityColors);
Color tintGrip;
Color tintExtra = chooseColor(extraColors);
boolean colorsAreSet = false;
do {
tintGrip = chooseColor(mainColors);
if (tintAffinity != tintBlade && tintAffinity != tintGrip
&& tintGrip != tintBlade) {
colorsAreSet = true;
}
} while (!colorsAreSet);
Pixmap pixmap = tex.getTextureData().consumePixmap();
for (int y = 0; y < pixmap.getHeight(); y++) {
for (int x = 0; x < pixmap.getWidth(); x++) {
Color color = new Color();
Color.rgba8888ToColor(color, pixmap.getPixel(x, y));
int colorInt[] = getColorFromHex(color);
if (colorInt[0] == colorBlade && colorInt[1] == colorBlade
&& colorInt[2] == colorBlade) {
pixmap.setColor(tintBlade);
pixmap.fillRectangle(x, y, 1, 1);
} else if (colorInt[0] == colorEdge && colorInt[1] == colorEdge
&& colorInt[2] == colorEdge) {
pixmap.setColor(tintEdge);
pixmap.fillRectangle(x, y, 1, 1);
} else if (colorInt[0] == colorAffinity
&& colorInt[1] == colorAffinity
&& colorInt[2] == colorAffinity) {
pixmap.setColor(tintAffinity);
pixmap.fillRectangle(x, y, 1, 1);
} else if (colorInt[0] == colorGrip && colorInt[1] == colorGrip
&& colorInt[2] == colorGrip) {
pixmap.setColor(tintGrip);
pixmap.fillRectangle(x, y, 1, 1);
}
else if (colorInt[0] == colorExtra && colorInt[1] == colorExtra
&& colorInt[2] == colorExtra) {
pixmap.setColor(tintExtra);
pixmap.fillRectangle(x, y, 1, 1);
}
}
}
tex = new Texture(pixmap);
textureData.disposePixmap();
pixmap.dispose();
return tex;
}
Run Code Online (Sandbox Code Playgroud)
我希望这有帮助。
请不要只是复制粘贴,尝试重建它以满足您的需要,否则您将学不到任何东西。
| 归档时间: |
|
| 查看次数: |
12443 次 |
| 最近记录: |