Android game engine andengine Learning Series 4: animated text for special effects

Source: Internet
Author: User

How to Learn efficiently is the most worth learning.

 

For text rendering and special effects, the andengine demo provides five text rendering examples. Here, I extract three of them and write a small demo. When I understand this, the rest will be clear.

First:

Three fonts are defined in this demo. The first one is the default simhei at the top, and the second one is the Custom font. The font style can be downloaded; the third type is a normal font stroke.

Here, some special effects are introduced, from transparency to opacity, and then rotation. For the control of these fonts and special effects, see the following code:

The overall code structure is the same as before. Here I only give the key code:

Onloadresources () method:

Public void onloadresources () {This. mfonttexture = new texture (256,256, textureoptions. bilinear_premultiplyalpha); this. mdroidfonttexture = new texture (256,256, textureoptions. bilinear_premultiplyalpha); this. mstrokefonttexture = new texture (256,256, textureoptions. bilinear_premultiplyalpha); // defines the default font. The parameter: the first is the texture defined above, the second is the font style, the third is the font size, and the fourth is whether the font is deprecated, the fifth is the color this. mfont = new font (this. mfonttexture, typeface. create (typeface. default, typeface. bold), 32, true, color. black); fontlist. add (this. mfont); // The Custom font. Parameter: the first is the texture defined above, the second is the context, and the third is the font path, the fourth is the font size, the fifth is the offset, and the sixth is the color this. ifont = fontfactory. createfromasset (this. mdroidfonttexture, this, "droid. TTF ", 32, true, color. black); fontlist. add (this. ifont); // Note 1 // define the stroke of the font. parameters: the first parameter is the texture defined above, and the second parameter is the font style, the third parameter is the font size, the fourth parameter is whether or not to offset, the fifth parameter is the font color, and the sixth parameter is the width of the font edge, the seventh parameter is the second side color this. mstrokefont = new strokefont (this. mstrokefonttexture, typeface. create (typeface. default, typeface. bold), 32, true, color. black, 2, color. white); fontlist. add (this. mstrokefont); // load three textures this. mengine. gettexturemanager (). loadtextures (this. mfonttexture, this. mdroidfonttexture, this. mstrokefonttexture); // load three fonts this. mengine. getfontmanager (). loadfonts (this. mfont, this. ifont, this. mstrokefont );}

Onloadscene () method:

Public scene onloadscene () {This. mengine. registerupdatehandler (New fpslogger (); final scene = new scene (1); scene. setbackground (New colorbackground (0.09804f, 0.6274f, 0.8784f); For (INT I = 0; I <fontlist. size (); I ++) {tickertext text = new tickertext (50, (I + 1) * 100, fontlist. get (I), "Hello everyone, this is duancanmeng's blog! ", Horizontalalign. center, 5); text. addshapemodifier (new partition (New parallelshapemodifier (New alphamodifier (10, 0.0f, 1.0f), new scalemodifier (10, 0.5f, 1.0f), new rotationmodifier (5, 0,360 ))); // note 2text. setblendfunction (gl10.gl _ src_alpha, gl10.gl _ one_minus_src_alpha); // you have mentioned scene in the previous sections. gettoplayer (). addentity (text);} return scene ;}

NOTE 1: The font style of this area can be.

Note 2: The parameters in the tickertext constructor are well understood. The last two parameters are explained as follows: The last two parameters indicate that the font is center-aligned, the first to last is the number of characters displayed in one second, that is, the speed at which words are drawn. You can see that the special effect is from the code text. when addshapemodifier is loaded, sequenceshapemodifier indicates that all actions in the table are executed in sequence. parallelshapemodifier indicates that all actions in the table are executed at the same time, and all the parameters in the modifier include, the first is the execution time, the second is the status before execution, and the third is the status after execution. Example: New
Alphamodifier (10, 0.0f, 1.0f) indicates that the text changes from transparent to opaque within 10 seconds.

 

 

 

 

 

 

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.