Cocos2d-iPhone V3 (2) scenario Conversion
Cocos2d-iPhone V3 (2) scenario Conversion
-
- 1. Preparations
Can I create a scenario?
#import cocos2d.h#import cocos2d-ui.h@interface MainScene : CCScene+ (MainScene *)scene;- (id)init;@end
The basic methods must be implemented,scene
,init
,onEnter
,onExit
AndtouchBegan
. If not, first look at the Cocos2d-iPhone V3 (1) BASIC Program Framework and Common Action Introduction This.
Now, assume that you have created two custom scenario classes.MainScene
AndHomeScene
.
2. Transfer!SlaveMainScene
ConvertHomeScene
, InMainScene
In a code:
CCTransition *t = [CCTransition transitionPushWithDirection:CCTransitionDirectionRight duration:1.0f][CCDirector sharedDirector] replaceScene:[HomeScene scene] withTransition:t];
CreateCCTransition
And then let the Director hold the audience.CCTransition
To transferHomeScene
, The function used is:
- (void)replaceScene:(CCScene *)scene withTransition:(CCTransition *)transition;
You need to feel like a movie director. Here are four elements of transition:
- Old scenarios
- New scenarios
- Transfer Mode: parameters such as transfer direction may be involved
- Transfer Time 3. Common Transfer Modes
The above ispush
, Specifically, the new scene is moved from the right to the left (to push the old scene to the left ). The six transfer methods are as follows:
// Note: The following statement is not formal, just to be brief and clear // cross fadetransitionCrossFadeWithDuration :( NSTimeInterval) // fade with colortransitionFadeWithColor :( CCColor *) duration :( NSTimeInterval) // interval :( NSTimeInterval) // move interval :( CCTransitionDirection) duration :( NSTimeInterval) // interval :( duration) duration :( NSTimeInterval) // interval :( CCTransitionDirection) duration :( NSTimeInterval)
- In cross fade, the alpha value of the old scenario changes from 1 to 0, the alpha value of the new scenario changes from 0 to 1, and the two cross nodes are combined.
- Fade with color is to add a color scene between the old scene and the new scene, first from the old scene cross fade to the color scene, then from the color scene cross fade to the new scene.
- Fade is a special case of fade with color, that is, the color scene is black.
- The move in field refers to the move in field in the new scenario, that is, the new scene is moved to the old scenario like a lid.
- In the new scenario, the push field is used to push the old scenario, and the two scenarios are moved in parallel.
- Reveal transfer refers to the old scenario under the new scenario, and then the old one is removed like the old one, and the new one is revealed. In contrast to moving in, one is built in a new scenario, and the other is revealed in an old scenario.
As a matter of fact, you can try coding and get a little longer to observe the duration settings.
-
Reprinted please indicate from: http://blog.csdn.net/prevention