我想做一個馬里奧遊戲克隆,現在,在我的構造函數中,我有一個方法,應該使某種顏色透明,而不是當前粉紅色(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