[Cocos2d-x Study Notes] text input, menu, memory management, Timer

Source: Internet
Author: User

Text input

Cctextfiledttf

Cctextfiledttf * textedit = cctextfiledttf: textfiledwithzaceholder ("input", "Arial", 33 );

Textedit-> atchwithime (); the keyboard is displayed.

Textedit-> setsecuretextentry (true); password format input

 

Cceditbox

Ccscale9sprite * BG = ccscale9sprite: Create ("abc.png"); 9 Mei map is easy to expand, saving resources

Cceditbox * editbox = cceditbox: Create (ccsize (100, 30), BG );

Editbox-> setplaceholder ("input here"); displays text by default

Editbox-> setinputflag (...); in various cases, such as uppercase letters and Case sensitivity.

 

Menu

Ccmenuitemfont * Item = ccmenuitemfont: Create ("this is item"); the default location is in the center

Menu-> addchid (item );

Ccmenu * menu = ccmenu: Create ();

Addchild (menu );

Set the corresponding function

Item-> settarget (this, menu_selector (function pointer ));

Void menu: menuhandler (cccobject *)

{

 

}

 

Menuitems

Ccmenuitematlasfont * itemaltas = ccmenuitematlasfont: Create ("123456", "labelatlasimg.png", 24, 32, '0 ');

Ccmenuitemimage * itemimage = ccmenuitemimaage: Create ("closenormal.png", "closesected.png ");

Ccmenuitemlabel * itemlabel = ccmenuitemlabel: Create (

Cclabelttf: Create ("this is lable TTF item", "Arial", 33 );

);

Ccmenuitemlabel * itemlableibmfont = ccmenuitemlabel: Create ();

 

Ccmenuitemtoggle * itemtoggle = ccmenuitemtoggle: createwithtarget ();

 

Vertical Alignment

Menu-> alignitemsvertically ();

 

Cocos Memory Management

C ++ constructor is language-Level Initialization

Init is the initialization of the Cocos service layer.

 

Coocs uses semi-automated Memory Management

Create () = Automatic Management

 

Memory Manager-> Access Reference Counter

New

Release ()

Retain () reference counter plus 1

Autorelease adds this object to the Memory Manager

 

Cocos semi-automatic memory management is implemented by ccobject

Counter

Counter setting function

 

For retain () objects, to avoid Memory leakage

Two methods can be used: release ();

~ Destructor ()

{

_ Arr-> release ();

}

 

Void onexit ()

{

Parent class: onexit (); The onexit () function of the parent class must be called first; otherwise, larger memory leakage will occur.

_ Arr-> release ();

}

 

Scheduleupdate (); let the frame call this-> Update (float DT) function cyclically

Void helloworld: handeer (ccobject * sender)
{
Ccnode * node = (ccnode *) sender;
Haha = node-> gettag ()-1000;
}

Void helloworld: Update (float delta)
{
If (1 = haha)
{
SP-> setpositiony (SP-> getpositiony () + 150 * delta );
Cclog ("1 ");
}
If (2 = haha)
{
SP-> setpositiony (SP-> getpositiony ()-150 * delta );
Cclog ("2 ");
}
If (3 = haha)
{
SP-> setpositionx (SP-> getpositionx ()-150 * delta );
Cclog ("3 ");
}
If (4 = haha)
{
SP-> setpositionx (SP-> getpositionx () + 150 * delta );
Cclog ("4 ");
}

Return;
}

[Cocos2d-x Study Notes] text input, menu, memory management, Timer

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.