我想做一个马里奥游戏克隆,现在,在我的构造函数中,我有一个方法,应该使某种颜色透明,而不是当前粉红色(R:255,G:0,B: 254)。根据Photoshop,十六进制值是ff00fe。我的方法是:为什么我的方法不能去除这种颜色?
public Mario(){
this.state = MarioState.SMALL;
this.x = 54;
this.y = 806;
URL spriteAtLoc = getClass().getResource("sprites/Mario/SmallStandFaceRight.bmp");
try{
sprite = ImageIO.read(spriteAtLoc);
int width = sprite.getWidth();
int height = sprite.getHeight();
int[] pixels = new int[width * height];
sprite.getRGB(0, 0, width, height, pixels, 0, width);
for (int i = 0; i < pixels.length; i++) {
if (pixels[i] == 0xFFff00fe) {
pixels[i] = 0x00ff00fe; //this is supposed to set alpha value to 0 and make the target color transparent
}
}
} catch(IOException e){
System.out.println("sprite not found");
e.printStackTrace();
}
}
它运行和编译,但精灵出来完全一样,当我呈现它。 (编辑:也许注意到我没有super.paintComponent方法(G)在我的paintComponent(G)方法中的精灵是.bmps
你能解释一下什么用确切的问题精灵更详细吗? – SteelToe
我想,有时间做一些调试。 –
它应该是一个超级马里奥的精灵,它是以bmp格式;因为它的全部都是正方形,所以不是马里奥的像素是我想在绘制时变成透明的颜色。 – Derry