Efficient game development and learning & amp; beautiful display points

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.