PageRenderTime 126ms CodeModel.GetById 17ms app.highlight 103ms RepoModel.GetById 1ms app.codeStats 0ms

/libs/cocos2d/CCTransition.m

http://github.com/kstenerud/ObjectAL-for-iPhone
Objective C | 1046 lines | 730 code | 173 blank | 143 comment | 26 complexity | f0e9f9f5ffca8b8dbdb4fc517ac62d6c MD5 | raw file
   1/*
   2 * cocos2d for iPhone: http://www.cocos2d-iphone.org
   3 *
   4 * Copyright (c) 2008-2010 Ricardo Quesada
   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
  28#import "CCTransition.h"
  29#import "CCNode.h"
  30#import "CCDirector.h"
  31#import "CCIntervalAction.h"
  32#import "CCInstantAction.h"
  33#import "CCCameraAction.h"
  34#import "CCLayer.h"
  35#import "CCCamera.h"
  36#import "CCTiledGridAction.h"
  37#import "CCEaseAction.h"
  38#import "CCTouchDispatcher.h"
  39#import "CCRenderTexture.h"
  40#import "Support/CGPointExtension.h"
  41
  42enum {
  43	kSceneFade = 0xFADEFADE,
  44};
  45
  46@interface CCTransitionScene (Private)
  47-(void) sceneOrder;
  48- (void)setNewScene:(ccTime)dt;
  49@end
  50
  51@implementation CCTransitionScene
  52+(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s
  53{
  54	return [[[self alloc] initWithDuration:t scene:s] autorelease];
  55}
  56
  57-(id) initWithDuration:(ccTime) t scene:(CCScene*)s
  58{
  59	NSAssert( s != nil, @"Argument scene must be non-nil");
  60	
  61	if( (self=[super init]) ) {
  62	
  63		duration = t;
  64		
  65		// retain
  66		inScene = [s retain];
  67		outScene = [[CCDirector sharedDirector] runningScene];
  68		[outScene retain];
  69		
  70		NSAssert( inScene != outScene, @"Incoming scene must be different from the outgoing scene" );
  71		
  72		// disable events while transitions
  73		[[CCTouchDispatcher sharedDispatcher] setDispatchEvents: NO];
  74
  75		[self sceneOrder];
  76	}
  77	return self;
  78}
  79-(void) sceneOrder
  80{
  81	inSceneOnTop = YES;
  82}
  83
  84-(void) draw
  85{
  86	if( inSceneOnTop ) {
  87		[outScene visit];
  88		[inScene visit];
  89	} else {
  90		[inScene visit];
  91		[outScene visit];
  92	}
  93}
  94
  95-(void) finish
  96{
  97	/* clean up */	
  98	[inScene setVisible:YES];
  99	[inScene setPosition:ccp(0,0)];
 100	[inScene setScale:1.0f];
 101	[inScene setRotation:0.0f];
 102	[inScene.camera restore];
 103	
 104	[outScene setVisible:NO];
 105	[outScene setPosition:ccp(0,0)];
 106	[outScene setScale:1.0f];
 107	[outScene setRotation:0.0f];
 108	[outScene.camera restore];
 109	
 110	[self schedule:@selector(setNewScene:) interval:0];
 111}
 112
 113-(void) setNewScene: (ccTime) dt
 114{	
 115	[self unschedule:_cmd];
 116	
 117	CCDirector *director = [CCDirector sharedDirector];
 118	
 119	// Before replacing, save the "send cleanup to scene"
 120	sendCleanupToScene = [director sendCleanupToScene];
 121	
 122	[director replaceScene: inScene];
 123	
 124	// enable events while transitions
 125	[[CCTouchDispatcher sharedDispatcher] setDispatchEvents: YES];
 126	
 127	// issue #267
 128	[outScene setVisible:YES];	
 129}
 130
 131-(void) hideOutShowIn
 132{
 133	[inScene setVisible:YES];
 134	[outScene setVisible:NO];
 135}
 136
 137// custom onEnter
 138-(void) onEnter
 139{
 140	[super onEnter];
 141	[inScene onEnter];
 142	// outScene should not receive the onEnter callback
 143}
 144
 145// custom onExit
 146-(void) onExit
 147{
 148	[super onExit];
 149	[outScene onExit];
 150
 151	// inScene should not receive the onExit callback
 152	// only the onEnterTransitionDidFinish
 153	[inScene onEnterTransitionDidFinish];
 154}
 155
 156// custom cleanup
 157-(void) cleanup
 158{
 159	[super cleanup];
 160	
 161	if( sendCleanupToScene )
 162	   [outScene cleanup];
 163}
 164
 165-(void) dealloc
 166{
 167	[inScene release];
 168	[outScene release];
 169	[super dealloc];
 170}
 171@end
 172
 173//
 174// Oriented Transition
 175//
 176@implementation CCOrientedTransitionScene
 177+(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s orientation:(tOrientation)o
 178{
 179	return [[[self alloc] initWithDuration:t scene:s orientation:o] autorelease];
 180}
 181
 182-(id) initWithDuration:(ccTime) t scene:(CCScene*)s orientation:(tOrientation)o
 183{
 184	if( (self=[super initWithDuration:t scene:s]) )
 185		orientation = o;
 186	return self;
 187}
 188@end
 189
 190
 191//
 192// RotoZoom
 193//
 194@implementation CCRotoZoomTransition
 195-(void) onEnter
 196{
 197	[super onEnter];
 198	
 199	[inScene setScale:0.001f];
 200	[outScene setScale:1.0f];
 201	
 202	[inScene setAnchorPoint:ccp(0.5f, 0.5f)];
 203	[outScene setAnchorPoint:ccp(0.5f, 0.5f)];
 204	
 205	CCIntervalAction *rotozoom = [CCSequence actions: [CCSpawn actions:
 206								   [CCScaleBy actionWithDuration:duration/2 scale:0.001f],
 207								   [CCRotateBy actionWithDuration:duration/2 angle:360 *2],
 208								   nil],
 209								[CCDelayTime actionWithDuration:duration/2],
 210							nil];
 211	
 212	
 213	[outScene runAction: rotozoom];
 214	[inScene runAction: [CCSequence actions:
 215					[rotozoom reverse],
 216					[CCCallFunc actionWithTarget:self selector:@selector(finish)],
 217				  nil]];
 218}
 219@end
 220
 221//
 222// JumpZoom
 223//
 224@implementation CCJumpZoomTransition
 225-(void) onEnter
 226{
 227	[super onEnter];
 228	CGSize s = [[CCDirector sharedDirector] winSize];
 229	
 230	[inScene setScale:0.5f];
 231	[inScene setPosition:ccp( s.width,0 )];
 232
 233	[inScene setAnchorPoint:ccp(0.5f, 0.5f)];
 234	[outScene setAnchorPoint:ccp(0.5f, 0.5f)];
 235
 236	CCIntervalAction *jump = [CCJumpBy actionWithDuration:duration/4 position:ccp(-s.width,0) height:s.width/4 jumps:2];
 237	CCIntervalAction *scaleIn = [CCScaleTo actionWithDuration:duration/4 scale:1.0f];
 238	CCIntervalAction *scaleOut = [CCScaleTo actionWithDuration:duration/4 scale:0.5f];
 239	
 240	CCIntervalAction *jumpZoomOut = [CCSequence actions: scaleOut, jump, nil];
 241	CCIntervalAction *jumpZoomIn = [CCSequence actions: jump, scaleIn, nil];
 242	
 243	CCIntervalAction *delay = [CCDelayTime actionWithDuration:duration/2];
 244	
 245	[outScene runAction: jumpZoomOut];
 246	[inScene runAction: [CCSequence actions: delay,
 247								jumpZoomIn,
 248								[CCCallFunc actionWithTarget:self selector:@selector(finish)],
 249								nil] ];
 250}
 251@end
 252
 253//
 254// MoveInL
 255//
 256@implementation CCMoveInLTransition
 257-(void) onEnter
 258{
 259	[super onEnter];
 260	
 261	[self initScenes];
 262	
 263	CCIntervalAction *a = [self action];
 264
 265	[inScene runAction: [CCSequence actions:
 266						 [self easeActionWithAction:a],
 267						 [CCCallFunc actionWithTarget:self selector:@selector(finish)],
 268						 nil]
 269	];
 270	 		
 271}
 272-(CCIntervalAction*) action
 273{
 274	return [CCMoveTo actionWithDuration:duration position:ccp(0,0)];
 275}
 276
 277-(CCIntervalAction*) easeActionWithAction:(CCIntervalAction*)action
 278{
 279	return [CCEaseOut actionWithAction:action rate:2.0f];
 280//	return [EaseElasticOut actionWithAction:action period:0.4f];
 281}
 282
 283-(void) initScenes
 284{
 285	CGSize s = [[CCDirector sharedDirector] winSize];
 286	[inScene setPosition: ccp( -s.width,0) ];
 287}
 288@end
 289
 290//
 291// MoveInR
 292//
 293@implementation CCMoveInRTransition
 294-(void) initScenes
 295{
 296	CGSize s = [[CCDirector sharedDirector] winSize];
 297	[inScene setPosition: ccp( s.width,0) ];
 298}
 299@end
 300
 301//
 302// MoveInT
 303//
 304@implementation CCMoveInTTransition
 305-(void) initScenes
 306{
 307	CGSize s = [[CCDirector sharedDirector] winSize];
 308	[inScene setPosition: ccp( 0, s.height) ];
 309}
 310@end
 311
 312//
 313// MoveInB
 314//
 315@implementation CCMoveInBTransition
 316-(void) initScenes
 317{
 318	CGSize s = [[CCDirector sharedDirector] winSize];
 319	[inScene setPosition: ccp( 0, -s.height) ];
 320}
 321@end
 322
 323//
 324// SlideInL
 325//
 326
 327// The adjust factor is needed to prevent issue #442
 328// One solution is to use DONT_RENDER_IN_SUBPIXELS images, but NO
 329// The other issue is that in some transitions (and I don't know why)
 330// the order should be reversed (In in top of Out or vice-versa).
 331#define ADJUST_FACTOR 0.5f
 332@implementation CCSlideInLTransition
 333-(void) onEnter
 334{
 335	[super onEnter];
 336
 337	[self initScenes];
 338	
 339	CCIntervalAction *in = [self action];
 340	CCIntervalAction *out = [self action];
 341
 342	id inAction = [self easeActionWithAction:in];
 343	id outAction = [CCSequence actions:
 344					[self easeActionWithAction:out],
 345					[CCCallFunc actionWithTarget:self selector:@selector(finish)],
 346					nil];
 347	
 348	[inScene runAction: inAction];
 349	[outScene runAction: outAction];
 350}
 351-(void) sceneOrder
 352{
 353	inSceneOnTop = NO;
 354}
 355-(void) initScenes
 356{
 357	CGSize s = [[CCDirector sharedDirector] winSize];
 358	[inScene setPosition: ccp( -(s.width-ADJUST_FACTOR),0) ];
 359}
 360-(CCIntervalAction*) action
 361{
 362	CGSize s = [[CCDirector sharedDirector] winSize];
 363	return [CCMoveBy actionWithDuration:duration position:ccp(s.width-ADJUST_FACTOR,0)];
 364}
 365
 366-(CCIntervalAction*) easeActionWithAction:(CCIntervalAction*)action
 367{
 368	return [CCEaseOut actionWithAction:action rate:2.0f];
 369//	return [EaseElasticOut actionWithAction:action period:0.4f];
 370}
 371
 372@end
 373
 374//
 375// SlideInR
 376//
 377@implementation CCSlideInRTransition
 378-(void) sceneOrder
 379{
 380	inSceneOnTop = YES;
 381}
 382-(void) initScenes
 383{
 384	CGSize s = [[CCDirector sharedDirector] winSize];
 385	[inScene setPosition: ccp( s.width-ADJUST_FACTOR,0) ];
 386}
 387
 388-(CCIntervalAction*) action
 389{
 390	CGSize s = [[CCDirector sharedDirector] winSize];
 391	return [CCMoveBy actionWithDuration:duration position:ccp(-(s.width-ADJUST_FACTOR),0)];
 392}
 393
 394@end
 395
 396//
 397// SlideInT
 398//
 399@implementation CCSlideInTTransition
 400-(void) sceneOrder
 401{
 402	inSceneOnTop = NO;
 403}
 404-(void) initScenes
 405{
 406	CGSize s = [[CCDirector sharedDirector] winSize];
 407	[inScene setPosition: ccp(0,s.height-ADJUST_FACTOR) ];
 408}
 409
 410-(CCIntervalAction*) action
 411{
 412	CGSize s = [[CCDirector sharedDirector] winSize];
 413	return [CCMoveBy actionWithDuration:duration position:ccp(0,-(s.height-ADJUST_FACTOR))];
 414}
 415
 416@end
 417
 418//
 419// SlideInB
 420//
 421@implementation CCSlideInBTransition
 422-(void) sceneOrder
 423{
 424	inSceneOnTop = YES;
 425}
 426
 427-(void) initScenes
 428{
 429	CGSize s = [[CCDirector sharedDirector] winSize];
 430	[inScene setPosition: ccp(0,-(s.height-ADJUST_FACTOR)) ];
 431}
 432
 433-(CCIntervalAction*) action
 434{
 435	CGSize s = [[CCDirector sharedDirector] winSize];
 436	return [CCMoveBy actionWithDuration:duration position:ccp(0,s.height-ADJUST_FACTOR)];
 437}
 438@end
 439
 440//
 441// ShrinkGrow Transition
 442//
 443@implementation CCShrinkGrowTransition
 444-(void) onEnter
 445{
 446	[super onEnter];
 447	
 448	[inScene setScale:0.001f];
 449	[outScene setScale:1.0f];
 450
 451	[inScene setAnchorPoint:ccp(2/3.0f,0.5f)];
 452	[outScene setAnchorPoint:ccp(1/3.0f,0.5f)];	
 453	
 454	CCIntervalAction *scaleOut = [CCScaleTo actionWithDuration:duration scale:0.01f];
 455	CCIntervalAction *scaleIn = [CCScaleTo actionWithDuration:duration scale:1.0f];
 456
 457	[inScene runAction: [self easeActionWithAction:scaleIn]];
 458	[outScene runAction: [CCSequence actions:
 459					[self easeActionWithAction:scaleOut],
 460					[CCCallFunc actionWithTarget:self selector:@selector(finish)],
 461					nil] ];
 462}
 463-(CCIntervalAction*) easeActionWithAction:(CCIntervalAction*)action
 464{
 465	return [CCEaseOut actionWithAction:action rate:2.0f];
 466//	return [EaseElasticOut actionWithAction:action period:0.3f];
 467}
 468@end
 469
 470//
 471// FlipX Transition
 472//
 473@implementation CCFlipXTransition
 474-(void) onEnter
 475{
 476	[super onEnter];
 477	
 478	CCIntervalAction *inA, *outA;
 479	[inScene setVisible: NO];
 480
 481	float inDeltaZ, inAngleZ;
 482	float outDeltaZ, outAngleZ;
 483
 484	if( orientation == kOrientationRightOver ) {
 485		inDeltaZ = 90;
 486		inAngleZ = 270;
 487		outDeltaZ = 90;
 488		outAngleZ = 0;
 489	} else {
 490		inDeltaZ = -90;
 491		inAngleZ = 90;
 492		outDeltaZ = -90;
 493		outAngleZ = 0;
 494	}
 495		
 496	inA = [CCSequence actions:
 497		   [CCDelayTime actionWithDuration:duration/2],
 498		   [CCShow action],
 499		   [CCOrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:0 deltaAngleX:0],
 500		   [CCCallFunc actionWithTarget:self selector:@selector(finish)],
 501		   nil ];
 502	outA = [CCSequence actions:
 503			[CCOrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:outAngleZ deltaAngleZ:outDeltaZ angleX:0 deltaAngleX:0],
 504			[CCHide action],
 505			[CCDelayTime actionWithDuration:duration/2],							
 506			nil ];
 507	
 508	[inScene runAction: inA];
 509	[outScene runAction: outA];
 510	
 511}
 512@end
 513
 514//
 515// FlipY Transition
 516//
 517@implementation CCFlipYTransition
 518-(void) onEnter
 519{
 520	[super onEnter];
 521	
 522	CCIntervalAction *inA, *outA;
 523	[inScene setVisible: NO];
 524
 525	float inDeltaZ, inAngleZ;
 526	float outDeltaZ, outAngleZ;
 527
 528	if( orientation == kOrientationUpOver ) {
 529		inDeltaZ = 90;
 530		inAngleZ = 270;
 531		outDeltaZ = 90;
 532		outAngleZ = 0;
 533	} else {
 534		inDeltaZ = -90;
 535		inAngleZ = 90;
 536		outDeltaZ = -90;
 537		outAngleZ = 0;
 538	}
 539	inA = [CCSequence actions:
 540		   [CCDelayTime actionWithDuration:duration/2],
 541		   [CCShow action],
 542		   [CCOrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:90 deltaAngleX:0],
 543		   [CCCallFunc actionWithTarget:self selector:@selector(finish)],
 544		   nil ];
 545	outA = [CCSequence actions:
 546			[CCOrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:outAngleZ deltaAngleZ:outDeltaZ angleX:90 deltaAngleX:0],
 547			[CCHide action],
 548			[CCDelayTime actionWithDuration:duration/2],							
 549			nil ];
 550	
 551	[inScene runAction: inA];
 552	[outScene runAction: outA];
 553	
 554}
 555@end
 556
 557//
 558// FlipAngular Transition
 559//
 560@implementation CCFlipAngularTransition
 561-(void) onEnter
 562{
 563	[super onEnter];
 564	
 565	CCIntervalAction *inA, *outA;
 566	[inScene setVisible: NO];
 567
 568	float inDeltaZ, inAngleZ;
 569	float outDeltaZ, outAngleZ;
 570
 571	if( orientation == kOrientationRightOver ) {
 572		inDeltaZ = 90;
 573		inAngleZ = 270;
 574		outDeltaZ = 90;
 575		outAngleZ = 0;
 576	} else {
 577		inDeltaZ = -90;
 578		inAngleZ = 90;
 579		outDeltaZ = -90;
 580		outAngleZ = 0;
 581	}
 582	inA = [CCSequence actions:
 583			   [CCDelayTime actionWithDuration:duration/2],
 584			   [CCShow action],
 585			   [CCOrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:-45 deltaAngleX:0],
 586			   [CCCallFunc actionWithTarget:self selector:@selector(finish)],
 587			   nil ];
 588	outA = [CCSequence actions:
 589				[CCOrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:outAngleZ deltaAngleZ:outDeltaZ angleX:45 deltaAngleX:0],
 590				[CCHide action],
 591				[CCDelayTime actionWithDuration:duration/2],							
 592				nil ];
 593
 594	[inScene runAction: inA];
 595	[outScene runAction: outA];
 596}
 597@end
 598
 599//
 600// ZoomFlipX Transition
 601//
 602@implementation CCZoomFlipXTransition
 603-(void) onEnter
 604{
 605	[super onEnter];
 606	
 607	CCIntervalAction *inA, *outA;
 608	[inScene setVisible: NO];
 609	
 610	float inDeltaZ, inAngleZ;
 611	float outDeltaZ, outAngleZ;
 612	
 613	if( orientation == kOrientationRightOver ) {
 614		inDeltaZ = 90;
 615		inAngleZ = 270;
 616		outDeltaZ = 90;
 617		outAngleZ = 0;
 618	} else {
 619		inDeltaZ = -90;
 620		inAngleZ = 90;
 621		outDeltaZ = -90;
 622		outAngleZ = 0;
 623	}
 624	inA = [CCSequence actions:
 625		   [CCDelayTime actionWithDuration:duration/2],
 626		   [CCSpawn actions:
 627			[CCOrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:0 deltaAngleX:0],
 628			[CCScaleTo actionWithDuration:duration/2 scale:1],
 629			[CCShow action],
 630			nil],
 631		   [CCCallFunc actionWithTarget:self selector:@selector(finish)],
 632		   nil ];
 633	outA = [CCSequence actions:
 634			[CCSpawn actions:
 635			 [CCOrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:outAngleZ deltaAngleZ:outDeltaZ angleX:0 deltaAngleX:0],
 636			 [CCScaleTo actionWithDuration:duration/2 scale:0.5f],
 637			 nil],
 638			[CCHide action],
 639			[CCDelayTime actionWithDuration:duration/2],							
 640			nil ];
 641	
 642	inScene.scale = 0.5f;
 643	[inScene runAction: inA];
 644	[outScene runAction: outA];
 645}
 646@end
 647
 648//
 649// ZoomFlipY Transition
 650//
 651@implementation CCZoomFlipYTransition
 652-(void) onEnter
 653{
 654	[super onEnter];
 655	
 656	CCIntervalAction *inA, *outA;
 657	[inScene setVisible: NO];
 658	
 659	float inDeltaZ, inAngleZ;
 660	float outDeltaZ, outAngleZ;
 661
 662	if( orientation == kOrientationUpOver ) {
 663		inDeltaZ = 90;
 664		inAngleZ = 270;
 665		outDeltaZ = 90;
 666		outAngleZ = 0;
 667	} else {
 668		inDeltaZ = -90;
 669		inAngleZ = 90;
 670		outDeltaZ = -90;
 671		outAngleZ = 0;
 672	}
 673	
 674	inA = [CCSequence actions:
 675			   [CCDelayTime actionWithDuration:duration/2],
 676			   [CCSpawn actions:
 677				 [CCOrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:90 deltaAngleX:0],
 678				 [CCScaleTo actionWithDuration:duration/2 scale:1],
 679				 [CCShow action],
 680				 nil],
 681			   [CCCallFunc actionWithTarget:self selector:@selector(finish)],
 682			   nil ];
 683	outA = [CCSequence actions:
 684				[CCSpawn actions:
 685				 [CCOrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:outAngleZ deltaAngleZ:outDeltaZ angleX:90 deltaAngleX:0],
 686				 [CCScaleTo actionWithDuration:duration/2 scale:0.5f],
 687				 nil],							
 688				[CCHide action],
 689				[CCDelayTime actionWithDuration:duration/2],							
 690				nil ];
 691
 692	inScene.scale = 0.5f;
 693	[inScene runAction: inA];
 694	[outScene runAction: outA];
 695}
 696@end
 697
 698//
 699// ZoomFlipAngular Transition
 700//
 701@implementation CCZoomFlipAngularTransition
 702-(void) onEnter
 703{
 704	[super onEnter];
 705	
 706	CCIntervalAction *inA, *outA;
 707	[inScene setVisible: NO];
 708	
 709	float inDeltaZ, inAngleZ;
 710	float outDeltaZ, outAngleZ;
 711	
 712	if( orientation == kOrientationRightOver ) {
 713		inDeltaZ = 90;
 714		inAngleZ = 270;
 715		outDeltaZ = 90;
 716		outAngleZ = 0;
 717	} else {
 718		inDeltaZ = -90;
 719		inAngleZ = 90;
 720		outDeltaZ = -90;
 721		outAngleZ = 0;
 722	}
 723		
 724	inA = [CCSequence actions:
 725		   [CCDelayTime actionWithDuration:duration/2],
 726		   [CCSpawn actions:
 727			[CCOrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:-45 deltaAngleX:0],
 728			[CCScaleTo actionWithDuration:duration/2 scale:1],
 729			[CCShow action],
 730			nil],						   
 731		   [CCShow action],
 732		   [CCCallFunc actionWithTarget:self selector:@selector(finish)],
 733		   nil ];
 734	outA = [CCSequence actions:
 735			[CCSpawn actions:
 736			 [CCOrbitCamera actionWithDuration: duration/2 radius: 1 deltaRadius:0 angleZ:outAngleZ deltaAngleZ:outDeltaZ angleX:45 deltaAngleX:0],
 737			 [CCScaleTo actionWithDuration:duration/2 scale:0.5f],
 738			 nil],							
 739			[CCHide action],
 740			[CCDelayTime actionWithDuration:duration/2],							
 741			nil ];
 742	
 743	inScene.scale = 0.5f;
 744	[inScene runAction: inA];
 745	[outScene runAction: outA];
 746}
 747@end
 748
 749
 750//
 751// Fade Transition
 752//
 753@implementation CCFadeTransition
 754+(id) transitionWithDuration:(ccTime)d scene:(CCScene*)s withColor:(ccColor3B)color
 755{
 756	return [[[self alloc] initWithDuration:d scene:s withColor:color] autorelease];
 757}
 758
 759-(id) initWithDuration:(ccTime)d scene:(CCScene*)s withColor:(ccColor3B)aColor
 760{
 761	if( (self=[super initWithDuration:d scene:s]) ) {
 762		color.r = aColor.r;
 763		color.g = aColor.g;
 764		color.b = aColor.b;
 765	}
 766	
 767	return self;
 768}
 769
 770-(id) initWithDuration:(ccTime)d scene:(CCScene*)s
 771{
 772	return [self initWithDuration:d scene:s withColor:ccBLACK];
 773}
 774
 775-(void) onEnter
 776{
 777	[super onEnter];
 778	
 779	CCColorLayer *l = [CCColorLayer layerWithColor:color];
 780	[inScene setVisible: NO];
 781	
 782	[self addChild: l z:2 tag:kSceneFade];
 783	
 784	
 785	CCNode *f = [self getChildByTag:kSceneFade];
 786	
 787	CCIntervalAction *a = [CCSequence actions:
 788						   [CCFadeIn actionWithDuration:duration/2],
 789						   [CCCallFunc actionWithTarget:self selector:@selector(hideOutShowIn)],
 790						   [CCFadeOut actionWithDuration:duration/2],
 791						   [CCCallFunc actionWithTarget:self selector:@selector(finish)],
 792						   nil ];
 793	[f runAction: a];
 794}
 795
 796-(void) onExit
 797{
 798	[super onExit];
 799	[self removeChildByTag:kSceneFade cleanup:NO];
 800}
 801@end
 802
 803
 804//
 805// Cross Fade Transition
 806//
 807@implementation CCCrossFadeTransition
 808
 809-(void) draw
 810{
 811	// override draw since both scenes (textures) are rendered in 1 scene
 812}
 813
 814-(void) onEnter
 815{
 816	[super onEnter];
 817	
 818	// create a transparent color layer
 819	// in which we are going to add our rendertextures
 820	ccColor4B  color = {0,0,0,0};
 821	CGSize size = [[CCDirector sharedDirector] winSize];
 822	CCColorLayer * layer = [CCColorLayer layerWithColor:color];
 823	
 824	// create the first render texture for inScene
 825	CCRenderTexture *inTexture = [CCRenderTexture renderTextureWithWidth:size.width height:size.height];
 826	inTexture.sprite.anchorPoint= ccp(0.5f,0.5f);
 827	inTexture.position = ccp(size.width/2, size.height/2);
 828	inTexture.anchorPoint = ccp(0.5f,0.5f);
 829	
 830	// render inScene to its texturebuffer
 831	[inTexture begin];
 832	[inScene visit];
 833	[inTexture end];
 834	
 835	// create the second render texture for outScene
 836	CCRenderTexture *outTexture = [CCRenderTexture renderTextureWithWidth:size.width height:size.height];
 837	outTexture.sprite.anchorPoint= ccp(0.5f,0.5f);
 838	outTexture.position = ccp(size.width/2, size.height/2);
 839	outTexture.anchorPoint = ccp(0.5f,0.5f);
 840	
 841	// render outScene to its texturebuffer
 842	[outTexture begin];
 843	[outScene visit];
 844	[outTexture end];
 845	
 846	// create blend functions
 847	
 848	ccBlendFunc blend1 = {GL_ONE, GL_ONE}; // inScene will lay on background and will not be used with alpha
 849	ccBlendFunc blend2 = {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}; // we are going to blend outScene via alpha 
 850	
 851	// set blendfunctions
 852	[inTexture.sprite setBlendFunc:blend1];
 853	[outTexture.sprite setBlendFunc:blend2];	
 854	
 855	// add render textures to the layer
 856	[layer addChild:inTexture];
 857	[layer addChild:outTexture];
 858	
 859	// initial opacity:
 860	[inTexture.sprite setOpacity:255];
 861	[outTexture.sprite setOpacity:255];
 862	
 863	// create the blend action
 864	CCIntervalAction * layerAction = [CCSequence actions:
 865									  [CCFadeTo actionWithDuration:duration opacity:0],
 866									  [CCCallFunc actionWithTarget:self selector:@selector(hideOutShowIn)],
 867									  [CCCallFunc actionWithTarget:self selector:@selector(finish)],
 868									  nil ];
 869	
 870	
 871	// run the blend action
 872	[outTexture.sprite runAction: layerAction];
 873	
 874	// add the layer (which contains our two rendertextures) to the scene
 875	[self addChild: layer z:2 tag:kSceneFade];
 876}
 877
 878// clean up on exit
 879-(void) onExit
 880{
 881	// remove our layer and release all containing objects 
 882	[self removeChildByTag:kSceneFade cleanup:NO];
 883	
 884	[super onExit];	
 885}
 886@end
 887
 888//
 889// TurnOffTilesTransition
 890//
 891@implementation CCTurnOffTilesTransition
 892
 893// override addScenes, and change the order
 894-(void) sceneOrder
 895{
 896	inSceneOnTop = NO;
 897}
 898
 899-(void) onEnter
 900{
 901	[super onEnter];
 902	CGSize s = [[CCDirector sharedDirector] winSize];
 903	float aspect = s.width / s.height;
 904	int x = 12 * aspect;
 905	int y = 12;
 906	
 907	id toff = [CCTurnOffTiles actionWithSize: ccg(x,y) duration:duration];
 908	id action = [self easeActionWithAction:toff];
 909	[outScene runAction: [CCSequence actions: action,
 910				   [CCCallFunc actionWithTarget:self selector:@selector(finish)],
 911				   [CCStopGrid action],
 912				   nil]
 913	 ];
 914
 915}
 916-(CCIntervalAction*) easeActionWithAction:(CCIntervalAction*)action
 917{
 918	return action;
 919//	return [EaseIn actionWithAction:action rate:2.0f];
 920}
 921@end
 922
 923#pragma mark Split Transitions
 924
 925//
 926// SplitCols Transition
 927//
 928@implementation CCSplitColsTransition
 929
 930-(void) onEnter
 931{
 932	[super onEnter];
 933
 934	inScene.visible = NO;
 935	
 936	id split = [self action];
 937	id seq = [CCSequence actions:
 938				split,
 939				[CCCallFunc actionWithTarget:self selector:@selector(hideOutShowIn)],
 940				[split reverse],
 941				nil
 942			  ];
 943	[self runAction: [CCSequence actions:
 944			   [self easeActionWithAction:seq],
 945			   [CCCallFunc actionWithTarget:self selector:@selector(finish)],
 946			   [CCStopGrid action],
 947			   nil]
 948	 ];
 949}
 950
 951-(CCIntervalAction*) action
 952{
 953	return [CCSplitCols actionWithCols:3 duration:duration/2.0f];
 954}
 955
 956-(CCIntervalAction*) easeActionWithAction:(CCIntervalAction*)action
 957{
 958	return [CCEaseInOut actionWithAction:action rate:3.0f];
 959}
 960@end
 961
 962//
 963// SplitRows Transition
 964//
 965@implementation CCSplitRowsTransition
 966-(CCIntervalAction*) action
 967{
 968	return [CCSplitRows actionWithRows:3 duration:duration/2.0f];
 969}
 970@end
 971
 972
 973#pragma mark Fade Grid Transitions
 974
 975//
 976// FadeTR Transition
 977//
 978@implementation CCFadeTRTransition
 979-(void) sceneOrder
 980{
 981	inSceneOnTop = NO;
 982}
 983
 984-(void) onEnter
 985{
 986	[super onEnter];
 987	
 988	CGSize s = [[CCDirector sharedDirector] winSize];
 989	float aspect = s.width / s.height;
 990	int x = 12 * aspect;
 991	int y = 12;
 992	
 993	id action  = [self actionWithSize:ccg(x,y)];
 994
 995	[outScene runAction: [CCSequence actions:
 996					[self easeActionWithAction:action],
 997				    [CCCallFunc actionWithTarget:self selector:@selector(finish)],
 998				    [CCStopGrid action],
 999				    nil]
1000	 ];
1001}
1002
1003-(CCIntervalAction*) actionWithSize: (ccGridSize) v
1004{
1005	return [CCFadeOutTRTiles actionWithSize:v duration:duration];
1006}
1007
1008-(CCIntervalAction*) easeActionWithAction:(CCIntervalAction*)action
1009{
1010	return action;
1011//	return [EaseIn actionWithAction:action rate:2.0f];
1012}
1013@end
1014
1015//
1016// FadeBL Transition
1017//
1018@implementation CCFadeBLTransition
1019-(CCIntervalAction*) actionWithSize: (ccGridSize) v
1020{
1021	return [CCFadeOutBLTiles actionWithSize:v duration:duration];
1022}
1023@end
1024
1025//
1026// FadeUp Transition
1027//
1028@implementation CCFadeUpTransition
1029-(CCIntervalAction*) actionWithSize: (ccGridSize) v
1030{
1031	return [CCFadeOutUpTiles actionWithSize:v duration:duration];
1032}
1033@end
1034
1035//
1036// FadeDown Transition
1037//
1038@implementation CCFadeDownTransition
1039-(CCIntervalAction*) actionWithSize: (ccGridSize) v
1040{
1041	return [CCFadeOutDownTiles actionWithSize:v duration:duration];
1042}
1043@end
1044
1045
1046