Cocos2d development and learning 4: Scenario transition effect and role of transition scenario

Source: Internet
Author: User

As we mentioned earlier, the game scenario is actually an abstract concept,
The most basic thing to learn about the content and needs of a scenario is to master his control and impact on the entire game process.

Here are the three main points of the scenario I have outlined.
1. Multi-scenario Structure
2. Transition animation for scene Switching

3. Functions of the transition scenario.

I. multiple scenarios
The first point is that we may use multiple scenarios in a game,
Better display of game logic
Ii. transition effect of scenario Switching
Scenario transition effect cocos2d provides the cctransitionscene class

Trace several methods in node

 
-(Void) onenter {/* init is called. If cctransitionscene is added, call */[Super onenter] after the transition scenario starts. cclog (@ "executed ~~ Onenter ");}-(void) onentertransitiondidfinish {/* This method will be called after onenter. If cctransitionscene is used, this method will be called after the transition effect ends */[Super onentertransitiondidfinish]; cclog (@ "executed ~~ Onentertransitiondidfinish ");}-(void) onexittransitiondidstart {cclog (@" executed ~~ Onexittransitiondidstart "); [Super onexittransitiondidstart];}-(void) onexit {// The node will call this method before calling the dealloc method. // If cctransitionscene is used, this method cclog (@ "executed ~~ Onexit "); [Super onexit];}

Then the call during execution

 
16:45:32. 893 loadingsim [2896: 1be03] executed ~~ OnEnter2012-07-17 16:45:32. 893 loadingsim [2896: 1be03] executed ~~ OnEnterTransitionDidFinish2012-07-17 16:45:37. 928 loadingsim [2896: 1be03] executed ~~ OnExitTransitionDidStart2012-07-17 16:45:42. 958 loadingsim [2896: 1be03] executed ~~ Onexit

TIPS: 1. If you want to override the above methods, you cannot forget to call the super method.
2. the preceding four logs are only used to track the logs of A on the four methods when Scenario A jumps to scenario B,
If we print the four methods in scenario B, we will find that the init and onenter methods of Method B are executed before onexit of method A, and the dealloc method of method A is executed at the end, this is the problem that memory will suddenly wait before the scenario is switched. The former has not dealloc, and the latter has init to initialize various memories.
In the document, the onexit method of a can release as much memory space as possible.
In scenario B, the memory allocation of various nodes should be placed after onentertransitiondidfinish (printing shows that the method is executed on onexit OF A) as much as possible, but this still needs to work with onexit of the former, if the former does not execute more memory release in onexit, the last release of a memory is still in dealloc, And the delloc of A is still behind onentertransitiondidfinish of B, it makes no sense ~
The document also mentions using an appointment method to adjust the transition time.

The transition effect of a scenario is simply to add a scenario conversion effect to provide a softer visual effect.

3. Application of transition scenarios
I think there are two core roles of transition scenarios.
1. Prevent latency and freezing caused by loading too much content in the new scenario during switching between the two scenarios. (This is easy to understand, for example, the concept of playing the World of Warcraft read progress bar scenario interface ~)
2. optimized the memory usage of scenario switching. To put it simply, for example, in scenario A, the memory occupies 100 mb. In scenario B, the memory required for Scenario B is also 100 MB, because we know that in scenario conversion, in scenario A, the memory is released before scenario B is loaded, so the memory may reach the peak of MB. The default value is "tempscene" in the transition scenario, the memory required by temp is 10 MB (because it is basically just a loading progress bar), then a-> temp-> B, the peak memory can be reduced to 110 MB.

For more information, see the uploaded learning tutorial ebook.

Notes:
1. Because the cocos2d-iPhone has now been updated to 2. + upper category changes
For example, cclabel is replaced by cclabelttf.
Ccslideinbtransition is changed to cctransitionslideint
There is also a change to the category name ~

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.