[Lgame entry school 013. Controls] lmessage of simple controls

Source: Internet
Author: User

[Lgame 013. Controls] lmessage for simple controls

Keyword: lgame entry control lmessage

What do you mean? Flowers? No, it's your heart ~

Reprinted please note, original address: http://blog.csdn.net/musicvs/article/details/7559567

LmessageIt was a very easy-to-use control. Why did I introduce it so late?

Sorry, I am a little embarrassed to say that, because I got stuck somewhere, I did some research to solve it ~

Okay. Start sharing ~

-

LmessageText Box, which is the most common type of RGB games, and can be printed word by word ~

Text Box, of course, there can be a box, it can be a pure color box, you can also use an image as the background box, Ren Jun select. Oh ~ Of course, you do not like the box ~

-

LmessageIs no different from other controls:

@ Override public void onload () {/* create a message box with a width and height of 120 and 180 respectively */MSG = new lmessage (120,180);/* set the background of the message box, you can also use an image as the background */MSG. setbackground (lcolor. cyan);/* set the coordinates of the message box */MSG. setlocation (100, 50);/* Add a message box to desktop */Add (MSG);/* key operation, set the maximum number of texts displayed per line. * If this setting is not available, you will have unexpected discoveries (you can try it yourself) */MSG. setmessagelength (4);/* set the text to a little longer, or you will not be able to see the setmessagelength effect ~ */Msg. setmessage ("bad ~ Dumb ~ ");}

Note the following two points:

1. lmessage is wide and high, and words beyond this range are not displayed.

2. Pay attention to the width and height of your text box ~! Set the maximum number of words displayed per line.

-

MeIt is stuck at 2nd points. I didn't set the maximum number of words to be displayed on each line before. When one line cannot be displayed, a strange problem occurs.

What's the problem? According to the normal way of thinking, a line cannot be displayed and no line breaks are set, that is, there are a few words not displayed.

-

YesIn fact, it is the first few words that do not display... comment out MSG. setmessagelength (4); run it to see:

Bad weatherA piece of cake ~ Because this situation is beyond my way of thinking, I thought that my operation was wrong, and I did not think it was caused by a line of incomplete display.

And, do you know how bad I am? The text I set is relatively short, so it is more difficult to find this problem... the first few words are always missing and should have been poorly displayed ~ Stupid wood ~.

-

So I went to study the source code. The research results are as follows.

OriginalBy default, lmessage displays a maximum of 10 characters in a row, which does not matter. The most important thing is that this number will affect the newline algorithm. The newline algorithm will change the initial X coordinate of the text to be drawn.

For example, when each line is limited to 10 characters, the initial coordinate of the draw text is assumed to be-80; then, if each line is limited to 20 characters, the initial coordinate of the drawn text may be-140 (assumed value ).

That is to say, the larger the number of words displayed in each line, the more the initial coordinates of the text drawn in each line will be left and become negative.

-

Well, I personally understand it as a "bug" (because it really bothers me...), but it does not have much impact. Just pay attention to the following two points:

1.
Whether the text box width is greater than or equal to the limit on the number of characters displayed in each line. For example, if one row contains five characters and each word is 20 characters in width, a row of words can have a maximum width of 100, make sure that the width of the text box is not smaller than this value.

2.
Note that lmessage displays 10 characters in each line by default. That is to say, if you do not set the limit of characters in each line, therefore, each line can have a maximum of 10*20 = 200 characters in width (assuming that the width of a word is 20), you must ensure that the width of the text box is not less than 200.

-

MostThen, try setting the maximum number of words in each line: msg. setmessagelength (4 );

Okay ~ Complete the process ~

Thank you for listening to me. See you next time.

-

Source code download: http://download.csdn.net/detail/musicvs/4295891

The original Article was first published on the Android-fans Forum:

Http://www.android-fans.net/thread-1717-1-1.html

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.