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