2017-03-17 3 views
1

그래서 나는 그것의 HUD의 점수가 게임을하기로되어있어하지만 난 코드흰색 화면 g.drawString

g.drawString("Score: " + score, 15, 64); 
//score is a variable 

를 사용할 때마다이 같은 흰색 화면이 나타납니다

enter image description here

는 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. 같다 나는 물건, 창문, 색채 등을 가지고 있지만 다른 수업을 듣고있다. P.P.S 내가 제거하면 해당 줄이 제대로 작동합니다. 나는 아무것도 글꼴이나 글꼴 색상을 선언 표시되지 않습니다

+0

.setBackground (Color.black)를 사용하여 배경색을 추가해야합니다. – Abi

+0

배경색, 물건 및 물건이 있지만 다른 클래스에 있습니다. – Stickzz107

답변

2

은 ...

g.setColor(Color.black); 
Font font = new Font("Times New Roman", Font.BOLD, (int) Math.round(20 * scaleX)); 
g.setFont(font); 
g.drawString("Score: " + score, 15, 64); 

난이 도움이되기를 바랍니다.