It is very important to show points beautifully in the game. The font of the mobile phone is too ugly, so we need to use pictures instead of numbers.
This is an Image resource. Create an Image array: Image [] imgNumbers = new Image [10]. Then read it.
Add this function to the integral part of your game.
/**
* Total score drawn
* @ Param g Graphics
* @ Param totalScore
*/
Private void drawTotalScore (Graphics g ){
// Convert the current total experience value into an array: for example, 2335 --> {0, 0, 2, 3, 3, 5 };
Int _ totalScore = totalScore; // totalScore is the total point in your game.
Int I = 0;
Int [] t = new int [6];
While (_ totalScore> 9 ){
T [I] = _ totalScore % 10;
_ TotalScore/= 10;
I ++;
}
T [I] = _ totalScore;
// Draw a number from the highest digit,
For (; I> = 0; I --){
G. drawImage (imgNumbers [t [I], offsetX + I * 10, y, Graphics. RIGHT | Graphics. TOP );
}
}
It's easy, isn't it? All data structures are used. At the beginning, I used to convert the int type into a String and then draw the image. Later I found that the super memory occupied and a lot of String garbage was generated. So I wrote this function, and the effect was good.