Simple usage of flex rotation Font/rotation bitmap/font to specify rotation center rotation/Timer

Source: Internet
Author: User

Implementation content: Text Rotation 1. --- rotation centered on the left vertex of the text

2. --- rotate in the center of a specified point

3. --- automatic rotation

Knowledge used: bitmap data, text display, drawing, timer, event listening

Keyword: textfield textformat bitmapdata bitmap sprite Timer

 

 

 

 

1. First, describe,
Textfield and bitmap can both be addchild to Sprite,
It is automatically placed at the left vertex of the display canvas.

2. textfield and bitmap all have the X and Y attributes to define the location of the parent container. Set their x and y values to change their display positions.

3. bitmapdata has the rect attribute, but it is read-only. Therefore, I understand that there is no concept of location, but we can define its size when creating it, that is, Set width and height. See the specific code below.

 

 

 

Solution 1: text can be displayed but cannot be rotated

Create text:

VaR S: SPRITE = new sprite;

// Place the Sprite in the parent container to be displayed

VaR T: textfield = new textfield;

T. Text = "2599 ";

// Set the font

VaR F: textformat = new textformat;

F. font = "airal ";

F. size = 30;

F. Color = 0x00ffff;

F. Bold = true;

// Set the font in the text

T. settextformat (f );

// Put the text in Sprite

S. addchild (t );

 

 

The text can be displayed.

Now let's rotate Sprite

S. Rotation = 10;

Result: The text disappears.

In fact, the text already exists at the position of rotation = 0. Although it is a child of Sprite, it cannot be rotated along with it.

 

 

Solution 2: text can be displayed and rotated for 10 degrees

VaR S: SPRITE = new sprite;

VaR T: textfield = new textfield;

T. Text = "2599 ";

VaR F: textformat = new textformat;

F. font = "airal ";

F. size = 30;

F. Color = 0x00ffff;

F. Bold = true;

T. settextformat (f );

// Convert text into a bitmap

// T. Width, T. height is the pixel height of the text. True indicates that it is transparent, and null indicates that there is no background color.

VaR B: bitmapdata = new bitmapdata (T. textwidth, T. textheight, true, null );

B. Draw (t );

// Think About It. Does setting T. X and then draw affect bitmapdata? ---------------------- Answer: No

VaR M: bitmap = new Bitmap (B );

M. X = 50;

S. addchild (m );

S. Rotation = 10;


Correctly rotated

 

Solution 3: text can be displayed and rotated for 10 degrees

VaR S: SPRITE = new sprite;

VaR T: textfield = new textfield;

T. Text = "2599 ";

VaR F: textformat = new textformat;

F. font = "airal ";

F. size = 30;

F. Color = 0x00ffff;

F. Bold = true;

T. settextformat (f );

VaR B: bitmapdata = new bitmapdata (T. Width, T. Height, true, null );

// What if T. textwidth is used above? --------------------- Incomplete text display

B. Draw (t );

S. Graphic. Clear ();

S. Graphic. beginbitmapfill (B );

S. Graphic. drawrect (400, 0, T. textwidth, T. textheight); // note, difference
T. textwidth and T. Width

S. graphic.
Endfill ();

S. Rotation = 10;


Correctly rotated

 

 

Solution 4: text display and automatic rotation



// Add Timer

VaR TM: timer = new timer (50 );

TM. Start ();

TM. addeventlistener (timerevent. Timer, timerfun );

 


Public Function timerfun (EV: timerevent): void // It must comply with the writing rules of the event function.

{

S. Rotation + = 10;

}


All right, all done.

Good luck ~~~~

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.