1
所以我應該做一個遊戲,在其HUD一個分數,但每當我使用的代碼出現在Java中,當我使用白色屏幕g.drawString
g.drawString("Score: " + score, 15, 64);
//score is a variable
出現白屏這樣
HUD的全碼是這樣的
import java.awt.Color;
import java.awt.Graphics;
public class HUD {
public static int HEALTH = 800;
private static int gvalue = 255;
public int score = 0;
public int level = 1;
public void tick(){
HEALTH = MainGame.clamp(HEALTH, 0, 800);
gvalue = MainGame.clamp(gvalue, 0, 255);
gvalue = HEALTH/4;
score++;
}
public void render(Graphics g){
g.setColor(Color.gray);
g.fillRect(15, 15, 200, 30);
g.setColor(new Color(70, gvalue, 0));
g.fillRect(15, 15, (HEALTH/4) , 30);
g.setColor(Color.white);
g.drawRect(15, 15, 100 * 2, 30);
g.drawString("Score: " + score, 15, 64);
//the line above though, when i remove it, it completely works
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
}
P. S我有物體,窗戶,顏色等,但他們在其他類。 P.P.S當我刪除,說的行,它工作正常。
您需要使用.setBackground(Color.black)添加背景顏色; – Abi
我有一個背景顏色,對象和東西,但他們在其他類。 – Stickzz107