문제

I want it to look symmetrical, but I can't work out why this doesn't work.

Font scoreFont = new Font("Impact", Font.PLAIN, 72);
    g.setFont(scoreFont);
    FontMetrics scoreFontMetrics = g.getFontMetrics();
    g.drawString("" + playerOneScore, SCREEN_WIDTH / 2
            - 30 - scoreFontMetrics.charWidth(playerOneScore),
            SCREEN_HEIGHT / 2);
    g.drawString("" + playerTwoScore,
            SCREEN_WIDTH / 2 + 30,
            SCREEN_HEIGHT / 2);

}

Thanks in advance.

Me

도움이 되었습니까?

해결책

The charWidth in FontMetrics gets a char as a parameter. If playerOneScore is an int than it is actually transformed to its char value and then that is applied to the method. You would be better using stringWidth(playerOneScore + "");

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top