好吧,我一直在看关于如何从一个spritesheet(8×8)采取精灵一对夫妇的YouTube视频和我导入雪碧真的DesignsByZepher喜欢的教程。但是他使用的方法导致他导入一个sorite板,然后将颜色更改为代码内选定的颜色。从精灵表
http://www.youtube.com/watch?v=6FMgQNDNMJc显示板
http://www.youtube.com/watch?v=7eotyB7oNHE的显色
我从看他的视频制作的代码是:
package exikle.learn.game.gfx;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
public class SpriteSheet {
public String path;
public int width;
public int height;
public int[] pixels;
public SpriteSheet(String path) {
BufferedImage image = null;
try {
image = ImageIO.read(SpriteSheet.class.getResourceAsStream(path));
} catch (IOException e) {
e.printStackTrace();
}
if (image == null) { return; }
this.path = path;
this.width = image.getWidth();
this.height = image.getHeight();
pixels = image.getRGB(0, 0, width, height, null, 0, width);
for (int i = 0; i < pixels.length; i++) {
pixels[i] = (pixels[i] & 0xff)/64;
}
}
}
^这是影像被导入的代码
package exikle.learn.game.gfx;
public class Colours {
public static int get(int colour1, int colour2, int colour3, int colour4) {
return (get(colour4) << 24) + (get(colour3) << 16)
+ (get(colour2) << 8) + get(colour1);
}
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 * 36 + g * 6 + b;
}
}
^和我认为处理所有颜色的代码,但我有点困惑。
我的问题是我如何为的就是删除颜色修正和刚刚导入并显示精灵表,所以它已经有颜色吗?