Learn iPhone and iPad cocos2d game development Reading Notes

Source: Internet
Author: User
Tags configuration settings

1.
"Fps_images.png" is cocos2d used to display the frame rate, that is, the number of frames displayed per second. You cannot delete or modify this image.

 

2.
Cocos2d memory management method:

1)
Call the static method for Object Instantiation: node.

Eg: ccnode * mynode = [ccnode node];

2)
The best way to instantiate an object in the future is to add mynode to the class inherited from ccnode, set the tag value, and then use the getchiledbytag method to extract it.

3)
. For details, see Chapter 2 page 15th.

 

3.
The _ cmd keyword is the abbreviation of the current method.

4.
The Director

1)
Director saves global configuration settings for cocos2d and manages cocos2d scenarios.

2)
Director is mainly used as follows:

A)
Access and change scenarios.

B)
Access cocos2d configuration details.

C)
Access Attempt (OpenGL, uiview, uiwindow)

D)
Pause, resume, and end the game.

E)
Convert coordinates between uikit and OpenGL.

3)
There are four types of ctor

A)
Ccdisplaylinkdirector, which is the most commonly used, is used internally by the apple cadisplaylink class and can be used only in ios3.1.

B)
Ccfastdirector.

C)
Ccthreadedfastdirector allows cocoa touch views to work with cocos2d. Disadvantages: power consumption.

D)
Cctimerdirector he is the slowest of the four ctor S.

 

5.
Pushing and poping

1)
1> purpose: to run a new scenario without removing the old scenario from the memory, so as to make the conversion scenario faster.

2)
2> side effects: memory usage increases.

3)
3> main application: Use a common scenario in many places, such as the pop-up setting menu. The advantage is that you no longer need to track where the "set scenario" was last opened.

 

6.
Cclayer common touch and targeted touch

1)
1> difference: Targeted touch receives a touch, which is usually a set of touch.

2)
Targeted processing allows you to remove some touch events from the queue. Other cclayers cannot receive this touch, improving efficiency.

2> application: Fuzzy

 

7.
Ccsprite

1)
1> the central point of the Sprite is the same as that in the lower left corner of the sprite.

 

8.
Anchorpoint of ccsprite

1)
Fuzzy Concept

 

9.
The texture size is 2 to the Npower

1)
1> otherwise, the IOS system will store the image in the nth power with the smallest 2, which will increase the memory usage.

2)
2> the contentsize attribute returns the actual image size.

 

10.
The Z parameter in addchild determines the node draw sequence. Nodes with the minimum Z value are first drawn, and the last node with the maximum Z value is drawn. If multiple nodes have the same Z value, their order of drawing will be determined by their order of adding.

 

11.
Do not call the array count method in the condition judgment of for or other loops, which can save several CPU cycles.

If the array is changed in the loop (delete or add an element), call the method to obtain the array count in the loop judgment.

 

12.
The update speed of the cclabel text is very slow, because the text above the cclabel is actually a texture, which needs to be generated through the IOS post rendering method, while also assigning a new texture and releasing the old one. The cclabel is only used for one generation and text display that is no longer changed. Of course, the change frequency is slow and there is no problem.

 

13.
Playing sound with simpleaudioengine

1)
Preferably MP3.

2)
The best sound format is caf.

 

14.
Ccdirector replacescene method call (optimization of memory usage is very important)

1)
When the ccdirereplreplacescene method is used to replace a scenario, each node calls the three methods included in ccnode. The three methods are onenter, onentertransitiondidfinish, and onexit.

2)
When switching between two scenarios (Scenario A and scenario B), the call sequence is as follows:

Sceneb init

Sceneb onenter

Scenea onexit

Sceneb onentertransitiondidfinish

Scenea dealloc

3)
Memory Saving Method

If you want to allocate memory-consuming nodes in the onentertransitiondidfinish method, you must first reserve a method or selector to allocate memory at least until the next frame, in this way, you can ensure that the previous scenario has been released from the memory. Another policy is to release as much memory as possible in the onexit method of the previous scenario.

4)
Solve the scenario switching latency solution.

The scenario is generated earlier than the scenario transition effect. If you execute complicated code or load a lot of materials in the init or onenter method, a delay will occur. The solution is to insert a loading scenario.

5)
Never call the replacescene method of ccdirector In the init method of a node.

Director cannot tolerate scenario replacement when a node is initialized

15.
Ccspritebatchnode Batch Processing

1)
When you use ccsprite, a rendering method is called every time a ccsprite node is generated, the overlay of system overhead caused by each rendering method call will reduce the Frame Rate of the game by about 15% or more.

2)
You can use ccspritebatchnode to display two or more ccsprite nodes.

3)
Because all ccsprite nodes are added to the same ccspritebatchnode, all ccsprite nodes use the same Z-order for rendering.

16.
Initialization notes

1)
Generally, in the default initialization method-(ID) Init, methods other than [Super init] should not be called.

17.
Load texture maps

1)
If you use a texture map set of 512*512 pixels or greater, you should load the texture before the game starts, it takes some time to load such a large texture (in the worst case, the game will be stuck for several 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.