/libs/cocos2d/CCPageTurnTransition.m
Objective C | 115 lines | 68 code | 15 blank | 32 comment | 4 complexity | 5ab2255927d5539e113558f93aec4c55 MD5 | raw file
Possible License(s): Apache-2.0
1/* 2 * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 * 4 * Copyright (c) 2009 Sindesso Pty Ltd http://www.sindesso.com/ 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 * copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 * THE SOFTWARE. 23 * 24 */ 25 26 27#import "CCPageTurnTransition.h" 28#import "CCPageTurn3DAction.h" 29#import "CCDirector.h" 30 31@implementation CCPageTurnTransition 32 33/** creates a base transition with duration and incoming scene */ 34+(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s backwards:(BOOL) back 35{ 36 return [[[self alloc] initWithDuration:t scene:s backwards:back] autorelease]; 37} 38 39/** initializes a transition with duration and incoming scene */ 40-(id) initWithDuration:(ccTime) t scene:(CCScene*)s backwards:(BOOL) back 41{ 42 // XXX: needed before [super init] 43 back_ = back; 44 45 if( ( self = [super initWithDuration:t scene:s] ) ) 46 { 47 // do something 48 } 49 return self; 50} 51 52-(void) sceneOrder 53{ 54 inSceneOnTop = back_; 55} 56 57// 58-(void) onEnter 59{ 60 [super onEnter]; 61 62 CGSize s = [[CCDirector sharedDirector] winSize]; 63 int x,y; 64 if( s.width > s.height) 65 { 66 x=16;y=12; 67 } 68 else 69 { 70 x=12;y=16; 71 } 72 73 id action = [self actionWithSize:ccg(x,y)]; 74 75 if(! back_ ) 76 { 77 [outScene runAction: [CCSequence actions: 78 action, 79 [CCCallFunc actionWithTarget:self selector:@selector(finish)], 80 [CCStopGrid action], 81 nil] 82 ]; 83 } 84 else 85 { 86 // to prevent initial flicker 87 inScene.visible = NO; 88 [inScene runAction: [CCSequence actions: 89 [CCShow action], 90 action, 91 [CCCallFunc actionWithTarget:self selector:@selector(finish)], 92 [CCStopGrid action], 93 nil] 94 ]; 95 } 96 97} 98 99-(CCIntervalAction*) actionWithSize: (ccGridSize) v 100{ 101 if( back_ ) 102 { 103 // Get hold of the PageTurn3DAction 104 return [CCReverseTime actionWithAction: 105 [CCPageTurn3D actionWithSize:v duration:duration]]; 106 } 107 else 108 { 109 // Get hold of the PageTurn3DAction 110 return [CCPageTurn3D actionWithSize:v duration:duration]; 111 } 112} 113 114@end 115