The draw function written by myself in the cocos2d-x will be called by myself
Put the painting code in draw.
For example:
Put a straight line below. This function cannot be drawn.
Bool HelloWorld: init ()
{
......
CcDrawLine (ccp (0, 0), ccp (s. width, s. height ));CHECK_GL_ERROR_DEBUG ();
......
}
The draw function can be drawn without calling it.
Void HelloWorld: draw ()
{
CcDrawLine (
the second method is better, then the next introduces the second method, let us be able to use Chinese in the cocos2d-x program, completely solve the Chinese garbled problem.
Second Implementation1 New XML file, according to a certain format, enter the corresponding Chinese to display, and finally must use UTF-8 format to save the file
[Html]
2. Code Implementation
[Cpp]/** Use Chinese in the cocos2d-x **/// Use CCDictionary to read xmlCCDictionary * strings = CCDictionary: createWithConte
Today's test found a problem with the game, System mail, if the tab, on Android on the open message content will be crash. And they're pretty sure it's the tab question.With my multi-month experience (indeed not for many years ...) See, never heard on Android because of a tab crash, and if there is this problem, there will certainly be a lot of people encounter, estimated long noisy, search for a bit, what information is not available.So write a test engineering test, respectively, under the Mac
, this can be left for later expansion.Next look at the Initnowalltiles method, the function of this method is to traverse all non-wall tile coordinates, for the subsequent method calls to prepare, play a cache data for speed purposes://initialization is not all tile coordinates of the wall, but also excludes (0,0), (0,1), (1,0) three tile.-(void) initnowalltiles{CgpointBADTILEPOS1 = CCP (0,0);CgpointBadTilePos2 =
*
_ Label;
Then, to prevent the memory cleanup operation from being forgotten, open helloworldscene. M and add some cleanupCode:
[_ Label release];_ Label
=
Nil;
Well, the next step is the focus. Similarly, in the helloworldscene. M file, replace the init method with the following code:
-
(ID) Init{
If
(Self
=
[Super init]) { Cgsize winsize=[[Ccdirector shareddire] winsize]; // Create a label for display purposes _ Label = [[Cclabelttf labelwithstring: @" L
There is a ccmessagebox in the Cocos2D-X that can be used to create a dialog box.
Ccmessagebox ("this is content", "title ");
This is common in Win32 and Android, and the underlying layer is to call the dialog box of the current system. The Win32 effect is as follows: the dialog of the called system on Android.
The dialog box is simple, but the system's dialog is not very nice. In actual development, there is generally no use of the system's dialog box, a word, too ugly! We can
Cocos2d-x by the way the text is shown in the following three:Cclabelttf: Use system fonts. Each string generates a texture. Low display efficiency, suitable for non-changing textCclabelatlas: use Nodeatlas to optimize rendering, suitable for often changing numbers, such as fractions, money, etc.Cclabelbmfont: using Ccspritebatchnode, very flexible, each character is a genie, able to operate on each character, use the picture directly. The text is drawn insets the font for text to CclabelttfSet
. Creating an instance using the static member function, create declares the following: static cccallfuncnd* Create ( ccobject * PSELECTORTARGET,SEL_CALLFUNCND selector,void * D) The callback function is executed by the Execute method, Execute in CCCALLFUNCND is implemented as follows:void Cccallfuncnd::execute () { if (m_ PCALLFUNCND) { (m_pselectortarget->*m_pcallfuncnd) (M_ptarget, m_pdata);} } by (M_pselectortarget->*m_pcallfuncnd) (M_ptarget, m_pdata), you
used, the 3rd parameter is the font size Cccontrolbutton *controlbutton = cccontrolbutton::create (Labelttf, BTN_NORAML);//Declare a button, the first argument is the declared text, the second argument is the declared picture Controlbutton->setbackgroundspriteforstate (Btn_down, cccontrolstatehighlighted);///Set the background image when the button is pressed, the first parameter is the declared picture, the second parameter is a constant value controlbutton->setposition (
First of all, for beginners, take a look at the cocos2d-x in the coordinate system of several concepts, reference http://blog.csdn.net/tskyfree/article/details/8292544. The others look down.Understanding the coordinate system is an important step in the beginning of development, in order not to let everyone dizzy, and now I go deep for everyone to explain,My original address: http://www.cnblogs.com/lyout/p/3292702.html.First we add two test sprites (w: 27, H: 40) into the scene:Ccsprite *sprite1
implementation of low-level modules, but rather on high-layer abstractions.For example, the wall switch should not rely on the switch implementation of the lamp, but should rely on an abstract switch standard interface, so that when we extend the program, our switch can also control other different lights, and even different electrical appliances. That is, electric lights and other electrical appliances inherit and implement our standard switching interfaces, and our switch producers do not nee
The horizontal version of the game is useful to multiple pictures appearing as dynamic backgrounds. But in the actual project, I found that the picture may have a gap when scrolling, affecting the game experience. After analysis, this is due to the time difference when resetting the buffered picture . Turns show the principle is a picture scrolling, the other as a buffer, scrolling out of the screen image and then replaced as a buffer, so that the cycle of rotation.To give an example:void Testsp
; Label.color = [Cccolor Redcolor]; The positive center of the screen is the Cartesian coordinate system, where the origin is in the lower left label.position = CCP (0.5f, 0.5f); [Self Addchild:label]; Create a Start button and click to go to the next scene ccbutton *helloworldbutton = [Ccbutton buttonwithtitle:@ "[Start]" fontname:@ "Verdana-bold" fon TSIZE:18.0F]; Helloworldbutton.positiontype = Ccpositiontypenormalized; In the m
"usingnamespacecocos2d::extension;//
(3) Compile the test comparison function:
/*** File: image resource name, for example, "sp.png" * index: Group of test data */void helloworld: Test (const char * file, int index) {// obtain the size of the visible area. ccsize mysize = ccdirector: shareddire()-> getvisiblesize (); // obtain the origin position of the visible area. ccpoint origin = ccdirector: shareddire () -> getvisibleorigin (); // ccpoint midpos = CCP
There are three ways to display text in a Cocos2d-X:
Cclabelttf: The system font is used. Each character string generates a texture, which is less efficient and suitable for non-changing text.
Cclabelatlas: Uses nodeatlas to optimize rendering. It is suitable for numbers that change frequently, such as scores and money.
Cclabelbmfont: it is flexible to use ccspritebatchnode. Each character is an genie. You can operate on each character and use the image directly to draw the text.
Set the text f
local actions = CCArray:array()actions:addObject(CCFadeOut:actionWithDuration(1))actions:addObject(CCFadeIn:actionWithDuration(1))sprite:runAction(CCRepeatForever:actionWithAction(CCSequence:actionsWithArray(actions)))4. ccspawn: run simultaneously
The final completion time of synchronization is determined by the time when the synchronization is completed in the basic action.
action1 = CCMoveTo:actionWithDuration(2, ccp(50, 50))action2 = CCRotateTo:
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