forked from cocos2d/cocos2d-objc
/
ActionsTest.m
1370 lines (1050 loc) · 31.7 KB
/
ActionsTest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// Actions Demo
// a cocos2d example
// http://www.cocos2d-iphone.org
//
// local import
#import "cocos2d.h"
#import "ActionsTest.h"
enum {
kTagAnimationDance = 1,
};
Class nextAction(void);
Class backAction(void);
Class restartAction(void);
static int sceneIdx=-1;
static NSString *transitions[] = {
@"ActionManual",
@"ActionMove",
@"ActionRotate",
@"ActionScale",
@"ActionSkew",
@"ActionSkewRotateScale",
@"ActionJump",
@"ActionBezier",
@"ActionBlink",
@"ActionFade",
@"ActionTint",
@"ActionAnimate",
@"ActionSequence",
@"ActionSequence2",
@"ActionSpawn",
@"ActionReverse",
@"ActionDelayTime",
@"ActionRepeat",
@"ActionRepeatForever",
@"ActionRotateToRepeat",
@"ActionRotateJerk",
@"ActionCallFunc",
@"ActionCallFuncND",
@"ActionCallBlock",
@"ActionReverseSequence",
@"ActionReverseSequence2",
@"ActionOrbit",
@"ActionFollow",
@"ActionProperty",
@"ActionTargeted",
@"Issue1305",
@"Issue1305_2",
@"Issue1288",
};
Class nextAction()
{
sceneIdx++;
sceneIdx = sceneIdx % ( sizeof(transitions) / sizeof(transitions[0]) );
NSString *r = transitions[sceneIdx];
Class c = NSClassFromString(r);
return c;
}
Class backAction()
{
sceneIdx--;
if( sceneIdx < 0 )
sceneIdx = sizeof(transitions) / sizeof(transitions[0]) -1;
NSString *r = transitions[sceneIdx];
Class c = NSClassFromString(r);
return c;
}
Class restartAction()
{
NSString *r = transitions[sceneIdx];
Class c = NSClassFromString(r);
return c;
}
@implementation ActionDemo
-(id) init
{
if( (self=[super init])) {
grossini = [[CCSprite alloc] initWithFile:@"grossini.png"];
tamara = [[CCSprite alloc] initWithFile:@"grossinis_sister1.png"];
kathia = [[CCSprite alloc] initWithFile:@"grossinis_sister2.png"];
[self addChild:grossini z:1];
[self addChild:tamara z:2];
[self addChild:kathia z:3];
CGSize s = [[CCDirector sharedDirector] winSize];
[grossini setPosition: ccp(s.width/2, s.height/3)];
[tamara setPosition: ccp(s.width/2, 2*s.height/3)];
[kathia setPosition: ccp(s.width/2, s.height/2)];
CCLabelTTF* label = [CCLabelTTF labelWithString:[self title] fontName:@"Arial" fontSize:32];
[self addChild: label];
[label setPosition: ccp(s.width/2, s.height-50)];
NSString *subtitle = [self subtitle];
if( subtitle ) {
CCLabelTTF* l = [CCLabelTTF labelWithString:subtitle fontName:@"Thonburi" fontSize:16];
[self addChild:l z:1];
[l setPosition:ccp(s.width/2, s.height-80)];
}
CCMenuItemImage *item1 = [CCMenuItemImage itemWithNormalImage:@"b1.png" selectedImage:@"b2.png" target:self selector:@selector(backCallback:)];
CCMenuItemImage *item2 = [CCMenuItemImage itemWithNormalImage:@"r1.png" selectedImage:@"r2.png" target:self selector:@selector(restartCallback:)];
CCMenuItemImage *item3 = [CCMenuItemImage itemWithNormalImage:@"f1.png" selectedImage:@"f2.png" target:self selector:@selector(nextCallback:)];
CCMenu *menu = [CCMenu menuWithItems:item1, item2, item3, nil];
menu.position = CGPointZero;
item1.position = ccp( s.width/2 - 100,30);
item2.position = ccp( s.width/2, 30);
item3.position = ccp( s.width/2 + 100,30);
[self addChild: menu z:1];
}
return self;
}
-(void) dealloc
{
[grossini release];
[tamara release];
[kathia release];
[super dealloc];
}
-(void) restartCallback: (id) sender
{
CCScene *s = [CCScene node];
[s addChild: [restartAction() node]];
[[CCDirector sharedDirector] replaceScene: s];
}
-(void) nextCallback: (id) sender
{
CCScene *s = [CCScene node];
[s addChild: [nextAction() node]];
[[CCDirector sharedDirector] replaceScene: s];
}
-(void) backCallback: (id) sender
{
CCScene *s = [CCScene node];
[s addChild: [backAction() node]];
[[CCDirector sharedDirector] replaceScene: s];
}
-(void) alignSpritesLeft:(unsigned int)numberOfSprites
{
CGSize s = [[CCDirector sharedDirector] winSize];
if( numberOfSprites == 1 ) {
tamara.visible = NO;
kathia.visible = NO;
[grossini setPosition:ccp(60, s.height/2)];
} else if( numberOfSprites == 2 ) {
[kathia setPosition: ccp(60, s.height/3)];
[tamara setPosition: ccp(60, 2*s.height/3)];
grossini.visible = NO;
} else if( numberOfSprites == 3 ) {
[grossini setPosition: ccp(60, s.height/2)];
[tamara setPosition: ccp(60, 2*s.height/3)];
[kathia setPosition: ccp(60, s.height/3)];
}
else {
CCLOG(@"ActionsTests: Invalid number of Sprites");
}
}
-(void) centerSprites:(unsigned int)numberOfSprites
{
CGSize s = [[CCDirector sharedDirector] winSize];
if( numberOfSprites == 0 ) {
tamara.visible = NO;
kathia.visible = NO;
grossini.visible = NO;
} else if( numberOfSprites == 1 ) {
tamara.visible = NO;
kathia.visible = NO;
[grossini setPosition:ccp(s.width/2, s.height/2)];
} else if( numberOfSprites == 2 ) {
[kathia setPosition: ccp(s.width/3, s.height/2)];
[tamara setPosition: ccp(2*s.width/3, s.height/2)];
grossini.visible = NO;
} else if( numberOfSprites == 3 ) {
[grossini setPosition: ccp(s.width/2, s.height/2)];
[tamara setPosition: ccp(2*s.width/3, s.height/2)];
[kathia setPosition: ccp(s.width/3, s.height/2)];
}
else {
CCLOG(@"ActionsTests: Invalid number of Sprites");
}
}
-(NSString*) title
{
return @"No title";
}
-(NSString*) subtitle
{
return nil;
}
@end
@implementation ActionManual
-(void) onEnter
{
[super onEnter];
CGSize s = [CCDirector sharedDirector].winSize;
tamara.scaleX = 2.5f;
tamara.scaleY = -1.0f;
tamara.position = ccp(100,70);
tamara.opacity = 128;
grossini.rotation = 120;
grossini.position = ccp(s.width/2, s.height/2);
grossini.color = ccc3( 255,0,0);
kathia.position = ccp(s.width-100, s.height/2);
kathia.color = ccBLUE;
}
-(NSString *) title
{
return @"Manual Transformation";
}
@end
@implementation ActionMove
-(void) onEnter
{
[super onEnter];
[self centerSprites:3];
CGSize s = [[CCDirector sharedDirector] winSize];
id actionTo = [CCMoveTo actionWithDuration: 2 position:ccp(s.width-40, s.height-40)];
id actionBy = [CCMoveBy actionWithDuration:2 position: ccp(80,80)];
id actionByBack = [actionBy reverse];
[tamara runAction: actionTo];
[grossini runAction: [CCSequence actions:actionBy, actionByBack, nil]];
[kathia runAction:[ CCMoveTo actionWithDuration:1 position:ccp(40,40)]];
}
-(NSString *) title
{
return @"MoveTo / MoveBy";
}
@end
@implementation ActionRotate
-(void) onEnter
{
[super onEnter];
[self centerSprites:3];
id actionTo = [CCRotateTo actionWithDuration: 2 angle:45];
id actionTo2 = [CCRotateTo actionWithDuration: 2 angle:-45];
id actionTo0 = [CCRotateTo actionWithDuration:2 angle:0];
[tamara runAction: [CCSequence actions:actionTo, actionTo0, nil]];
id actionBy = [CCRotateBy actionWithDuration:2 angle: 360];
id actionByBack = [actionBy reverse];
[grossini runAction: [CCSequence actions:actionBy, actionByBack, nil]];
[kathia runAction: [CCSequence actions:actionTo2, [[actionTo0 copy] autorelease], nil]];
}
-(NSString *) title
{
return @"RotateTo / RotateBy";
}
@end
@implementation ActionScale
-(void) onEnter
{
[super onEnter];
[self centerSprites:3];
id actionTo = [CCScaleTo actionWithDuration: 2 scale:0.5f];
id actionBy = [CCScaleBy actionWithDuration:2 scaleX:1 scaleY:10];
id actionBy2 = [CCScaleBy actionWithDuration:2 scaleX:5 scaleY:1];
[grossini runAction: actionTo];
[tamara runAction: [CCSequence actions:actionBy, [actionBy reverse], nil]];
[kathia runAction: [CCSequence actions:actionBy2, [actionBy2 reverse], nil]];
}
-(NSString *) title
{
return @"ScaleTo / ScaleBy";
}
@end
@implementation ActionSkew
-(void) onEnter
{
[super onEnter];
[self centerSprites:3];
id actionTo = [CCSkewTo actionWithDuration:2 skewX:37.2f skewY:-37.2f];
id actionToBack = [CCSkewTo actionWithDuration:2 skewX:0 skewY:0];
id actionBy = [CCSkewBy actionWithDuration:2 skewX:0.0f skewY:-90.0f];
id actionBy2 = [CCSkewBy actionWithDuration:2 skewX:45.0f skewY:45.0f];
id actionByBack = [actionBy reverse];
[tamara runAction:[CCSequence actions:actionTo, actionToBack, nil]];
[grossini runAction: [CCSequence actions:actionBy, actionByBack, nil]];
[kathia runAction: [CCSequence actions:actionBy2, [actionBy2 reverse], nil]];
}
-(NSString *) title
{
return @"SkewTo / SkewBy";
}
@end
@implementation ActionSkewRotateScale
-(void) onEnter
{
[super onEnter];
[tamara removeFromParentAndCleanup:YES];
[grossini removeFromParentAndCleanup:YES];
[kathia removeFromParentAndCleanup:YES];
CGSize boxSize = CGSizeMake(100.0f, 100.0f);
CCLayerColor *box = [CCLayerColor layerWithColor:ccc4(255,255,0,255)];
box.anchorPoint = ccp(0,0);
box.position = ccp(190,110);
box.contentSize = boxSize;
static CGFloat markerside = 10.0f;
CCLayerColor *uL = [CCLayerColor layerWithColor:ccc4(255,0,0,255)];
[box addChild:uL];
uL.contentSize = CGSizeMake(markerside, markerside);
uL.position = ccp(0.f, boxSize.height-markerside);
uL.anchorPoint = ccp(0,0);
CCLayerColor *uR = [CCLayerColor layerWithColor:ccc4(0,0,255,255)];
[box addChild:uR];
uR.contentSize = CGSizeMake(markerside, markerside);
uR.position = ccp(boxSize.width-markerside, boxSize.height-markerside);
uR.anchorPoint = ccp(0,0);
[self addChild:box];
id actionTo = [CCSkewTo actionWithDuration:2 skewX:0.f skewY:2.f];
id rotateTo = [CCRotateTo actionWithDuration:2 angle:61.0f];
id actionScaleTo = [CCScaleTo actionWithDuration:2 scaleX:-0.44f scaleY:0.47f];
id actionScaleToBack = [CCScaleTo actionWithDuration:2 scaleX:1.0f scaleY:1.0f];
id rotateToBack = [CCRotateTo actionWithDuration:2 angle:0];
id actionToBack = [CCSkewTo actionWithDuration:2 skewX:0 skewY:0];
[box runAction:[CCSequence actions:actionTo, actionToBack, nil]];
[box runAction:[CCSequence actions:rotateTo, rotateToBack, nil]];
[box runAction:[CCSequence actions:actionScaleTo, actionScaleToBack, nil]];
}
-(NSString *) title
{
return @"Skew + Rotate + Scale";
}
@end
@implementation ActionJump
-(void) onEnter
{
[super onEnter];
id actionTo = [CCJumpTo actionWithDuration:2 position:ccp(300,300) height:50 jumps:4];
id actionBy = [CCJumpBy actionWithDuration:2 position:ccp(300,0) height:50 jumps:4];
id actionUp = [CCJumpBy actionWithDuration:2 position:ccp(0,0) height:80 jumps:4];
id actionByBack = [actionBy reverse];
[tamara runAction: actionTo];
[grossini runAction: [CCSequence actions:actionBy, actionByBack, nil]];
[kathia runAction: [CCRepeatForever actionWithAction:actionUp]];
}
-(NSString *) title
{
return @"JumpTo / JumpBy";
}
@end
@implementation ActionBezier
-(void) onEnter
{
[super onEnter];
CGSize s = [[CCDirector sharedDirector] winSize];
//
// startPosition can be any coordinate, but since the movement
// is relative to the Bezier curve, make it (0,0)
//
// sprite 1
ccBezierConfig bezier;
bezier.controlPoint_1 = ccp(0, s.height/2);
bezier.controlPoint_2 = ccp(300, -s.height/2);
bezier.endPosition = ccp(300,100);
id bezierForward = [CCBezierBy actionWithDuration:3 bezier:bezier];
id bezierBack = [bezierForward reverse];
id seq = [CCSequence actions: bezierForward, bezierBack, nil];
id rep = [CCRepeatForever actionWithAction:seq];
// sprite 2
[tamara setPosition:ccp(80,160)];
ccBezierConfig bezier2;
bezier2.controlPoint_1 = ccp(100, s.height/2);
bezier2.controlPoint_2 = ccp(200, -s.height/2);
bezier2.endPosition = ccp(240,160);
id bezierTo1 = [CCBezierTo actionWithDuration:2 bezier:bezier2];
// sprite 3
[kathia setPosition:ccp(400,160)];
id bezierTo2 = [CCBezierTo actionWithDuration:2 bezier:bezier2];
[grossini runAction: rep];
[tamara runAction:bezierTo1];
[kathia runAction:bezierTo2];
}
-(NSString *) title
{
return @"BezierBy / BezierTo";
}
@end
@implementation ActionBlink
-(void) onEnter
{
[super onEnter];
[self centerSprites:3];
id action1 = [CCBlink actionWithDuration:3 blinks:10];
id action2 = [CCBlink actionWithDuration:3 blinks:5];
id action3 = [CCBlink actionWithDuration:0.5f blinks:5];
[tamara runAction: action1];
[kathia runAction:action2];
[grossini runAction:action3];
}
-(NSString *) title
{
return @"Blink";
}
@end
@implementation ActionFade
-(void) onEnter
{
[super onEnter];
[self centerSprites:2];
tamara.opacity = 0;
id action1 = [CCFadeIn actionWithDuration:1.0f];
id action1Back = [action1 reverse];
id action2 = [CCFadeOut actionWithDuration:1.0f];
id action2Back = [action2 reverse];
[tamara runAction: [CCSequence actions: action1, action1Back, nil]];
[kathia runAction: [CCSequence actions: action2, action2Back, nil]];
}
-(NSString *) title
{
return @"FadeIn / FadeOut";
}
@end
@implementation ActionTint
-(void) onEnter
{
[super onEnter];
[self centerSprites:2];
id action1 = [CCTintTo actionWithDuration:2 red:255 green:0 blue:255];
id action2 = [CCTintBy actionWithDuration:2 red:-127 green:-255 blue:-127];
id action2Back = [action2 reverse];
[tamara runAction: action1];
[kathia runAction: [CCSequence actions: action2, action2Back, nil]];
}
-(NSString *) title
{
return @"TintTo / TintBy";
}
@end
@implementation ActionAnimate
-(void) onEnter
{
[super onEnter];
[self centerSprites:2];
// Left: using manual animation.
CCAnimation* animation = [CCAnimation animation];
for( int i=1;i<15;i++)
[animation addFrameWithFilename: [NSString stringWithFormat:@"grossini_dance_%02d.png", i]];
id action = [CCAnimate actionWithDuration:2.8f animation:animation restoreOriginalFrame:YES];
[kathia runAction: [CCSequence actions: action, [action reverse], nil]];
// Right: Using new animation system
CCAnimationCache *cache = [CCAnimationCache sharedAnimationCache];
[cache addAnimationsWithFile:@"animations/animations-2.plist"];
CCAnimation *animation2 = [cache animationByName:@"dance_1"];
id action2 = [CCAnimate actionWithAnimation:animation2];
[tamara runAction: [CCSequence actions: action2, [action2 reverse], nil]];
observer_ = [[NSNotificationCenter defaultCenter] addObserverForName:CCAnimationFrameDisplayedNotification object:nil queue:nil usingBlock:^(NSNotification* notification) {
NSDictionary *userInfo = [notification userInfo];
NSLog(@"object %@ with data %@", [notification object], userInfo );
}];
}
-(void) onExit
{
[super onExit];
[[NSNotificationCenter defaultCenter] removeObserver:observer_];
}
-(NSString *) title
{
return @"Animation";
}
-(NSString*) subtitle
{
return @"Manual animation, and animation by parsing .plist";
}
@end
@implementation ActionSequence
-(void) onEnter
{
[super onEnter];
[self alignSpritesLeft:1];
id action = [CCSequence actions:
[CCMoveBy actionWithDuration: 2 position:ccp(240,0)],
[CCRotateBy actionWithDuration: 2 angle: 540],
nil];
[grossini runAction:action];
}
-(NSString *) title
{
return @"Sequence: Move + Rotate";
}
@end
@implementation ActionSequence2
-(void) onEnter
{
[super onEnter];
[self alignSpritesLeft:1];
[grossini setVisible:NO];
id action = [CCSequence actions:
[CCPlace actionWithPosition:ccp(200,200)],
[CCShow action],
[CCMoveBy actionWithDuration:1 position:ccp(100,0)],
[CCCallFunc actionWithTarget:self selector:@selector(callback1)],
[CCCallFuncN actionWithTarget:self selector:@selector(callback2:)],
[CCCallFuncND actionWithTarget:self selector:@selector(callback3:data:) data:(void*)0xbebabeba],
nil];
[grossini runAction:action];
}
-(void) callback1
{
CGSize s = [[CCDirector sharedDirector] winSize];
CCLabelTTF *label = [CCLabelTTF labelWithString:@"callback 1 called" fontName:@"Marker Felt" fontSize:16];
[label setPosition:ccp( s.width/4*1,s.height/2)];
[self addChild:label];
}
-(void) callback2:(id)sender
{
CGSize s = [[CCDirector sharedDirector] winSize];
CCLabelTTF *label = [CCLabelTTF labelWithString:@"callback 2 called" fontName:@"Marker Felt" fontSize:16];
[label setPosition:ccp( s.width/4*2,s.height/2)];
[self addChild:label];
}
-(void) callback3:(id)sender data:(void*)data
{
CGSize s = [[CCDirector sharedDirector] winSize];
CCLabelTTF *label = [CCLabelTTF labelWithString:@"callback 3 called" fontName:@"Marker Felt" fontSize:16];
[label setPosition:ccp( s.width/4*3,s.height/2)];
[self addChild:label];
}
-(NSString *) title
{
return @"Sequence of InstantActions";
}
@end
@implementation ActionSpawn
-(void) onEnter
{
[super onEnter];
[self alignSpritesLeft:1];
id action = [CCSpawn actions:
[CCJumpBy actionWithDuration:2 position:ccp(300,0) height:50 jumps:4],
[CCRotateBy actionWithDuration: 2 angle: 720],
nil];
[grossini runAction:action];
}
-(NSString *) title
{
return @"Spawn: Jump + Rotate";
}
@end
@implementation ActionRepeatForever
-(void) onEnter
{
[super onEnter];
[self centerSprites:1];
id action = [CCSequence actions:
[CCDelayTime actionWithDuration:1],
[CCCallFuncN actionWithTarget:self selector:@selector(repeatForever:)],
nil];
[grossini runAction:action];
}
-(void) repeatForever:(id)sender
{
CCRepeatForever *repeat = [CCRepeatForever actionWithAction: [CCRotateBy actionWithDuration:1.0f angle:360]];
// id repeat = [CCRepeat actionWithAction: [CCRotateBy actionWithDuration:1.0f angle:360] times:10];
[sender runAction:repeat];
}
-(NSString *) title
{
return @"CallFuncN + RepeatForever";
}
@end
@implementation ActionRotateToRepeat
-(void) onEnter
{
[super onEnter];
[self centerSprites:2];
id act1 = [CCRotateTo actionWithDuration:1 angle:90];
id act2 = [CCRotateTo actionWithDuration:1 angle:0];
id seq = [CCSequence actions:act1, act2, nil];
id rep1 = [CCRepeatForever actionWithAction:seq];
id rep2 = [CCRepeat actionWithAction:[[seq copy] autorelease] times:10];
[tamara runAction:rep1];
[kathia runAction:rep2];
}
-(NSString *) title
{
return @"Repeat/RepeatForever + RotateTo";
}
-(NSString *) subtitle
{
return @"You should see smooth movements (no jerks). issue #390";
}
@end
@implementation ActionRotateJerk
-(void) onEnter
{
[super onEnter];
[self centerSprites:2];
id seq = [CCSequence actions:
[CCRotateTo actionWithDuration:0.5f angle:-20],
[CCRotateTo actionWithDuration:0.5f angle:20],
nil];
id rep1 = [CCRepeat actionWithAction:seq times:10];
id rep2 = [CCRepeatForever actionWithAction: [[seq copy] autorelease] ];
[tamara runAction:rep1];
[kathia runAction:rep2];
}
-(NSString *) title
{
return @"RepeatForever / Repeat + Rotate";
}
-(NSString *) subtitle
{
return @"You should see smooth movements (no jerks). issue #390";
}
@end
@implementation ActionReverse
-(void) onEnter
{
[super onEnter];
[self alignSpritesLeft:1];
id jump = [CCJumpBy actionWithDuration:2 position:ccp(300,0) height:50 jumps:4];
id action = [CCSequence actions: jump, [jump reverse], nil];
[grossini runAction:action];
}
-(NSString *) title
{
return @"Reverse an action";
}
@end
@implementation ActionDelayTime
-(void) onEnter
{
[super onEnter];
[self alignSpritesLeft:1];
id move = [CCMoveBy actionWithDuration:1 position:ccp(150,0)];
id action = [CCSequence actions: move, [CCDelayTime actionWithDuration:2], move, nil];
[grossini runAction:action];
}
-(NSString *) title
{
return @"DelayTime: m + delay + m";
}
@end
@implementation ActionReverseSequence
-(void) onEnter
{
[super onEnter];
[self alignSpritesLeft:1];
id move1 = [CCMoveBy actionWithDuration:1 position:ccp(250,0)];
id move2 = [CCMoveBy actionWithDuration:1 position:ccp(0,50)];
id seq = [CCSequence actions: move1, move2, [move1 reverse], nil];
id action = [CCSequence actions: seq, [seq reverse], nil];
[grossini runAction:action];
}
-(NSString *) title
{
return @"Reverse a sequence";
}
@end
@implementation ActionReverseSequence2
-(void) onEnter
{
[super onEnter];
[self alignSpritesLeft:2];
// Test:
// Sequence should work both with IntervalAction and InstantActions
id move1 = [CCMoveBy actionWithDuration:1 position:ccp(250,0)];
id move2 = [CCMoveBy actionWithDuration:1 position:ccp(0,50)];
id tog1 = [CCToggleVisibility action];
id tog2 = [CCToggleVisibility action];
id seq = [CCSequence actions: move1, tog1, move2, tog2, [move1 reverse], nil];
id action = [CCRepeat actionWithAction:[CCSequence actions: seq, [seq reverse], nil]
times:3];
// Test:
// Also test that the reverse of Hide is Show, and vice-versa
[kathia runAction:action];
id move_tamara = [CCMoveBy actionWithDuration:1 position:ccp(100,0)];
id move_tamara2 = [CCMoveBy actionWithDuration:1 position:ccp(50,0)];
id hide = [CCHide action];
id seq_tamara = [CCSequence actions: move_tamara, hide, move_tamara2, nil];
id seq_back = [seq_tamara reverse];
[tamara runAction: [CCSequence actions: seq_tamara, seq_back, nil]];
}
-(NSString *) title
{
return @"Reverse sequence 2";
}
@end
@implementation ActionRepeat
-(void) onEnter
{
[super onEnter];
[self alignSpritesLeft:2];
id a1 = [CCMoveBy actionWithDuration:1 position:ccp(150,0)];
id action1 = [CCRepeat actionWithAction:
[CCSequence actions: [CCPlace actionWithPosition:ccp(60,60)], a1, nil]
times:3];
id action2 = [CCRepeatForever actionWithAction:
[CCSequence actions: [[a1 copy] autorelease], [a1 reverse], nil]
];
[kathia runAction:action1];
[tamara runAction:action2];
}
-(NSString *) title
{
return @"Repeat / RepeatForever actions";
}
@end
@implementation ActionCallFunc
-(void) onEnter
{
[super onEnter];
[self centerSprites:3];
id action = [CCSequence actions:
[CCMoveBy actionWithDuration:2 position:ccp(200,0)],
[CCCallFunc actionWithTarget:self selector:@selector(callback1)],
nil];
id action2 = [CCSequence actions:
[CCScaleBy actionWithDuration:2 scale: 2],
[CCFadeOut actionWithDuration:2],
[CCCallFuncN actionWithTarget:self selector:@selector(callback2:)],
nil];
id action3 = [CCSequence actions:
[CCRotateBy actionWithDuration:3 angle:360],
[CCFadeOut actionWithDuration:2],
[CCCallFuncND actionWithTarget:self selector:@selector(callback3:data:) data:(void*)0xbebabeba],
nil];
[grossini runAction:action];
[tamara runAction:action2];
[kathia runAction:action3];
}
-(void) callback1
{
NSLog(@"callback 1 called");
CGSize s = [[CCDirector sharedDirector] winSize];
CCLabelTTF *label = [CCLabelTTF labelWithString:@"callback 1 called" fontName:@"Marker Felt" fontSize:16];
[label setPosition:ccp( s.width/4*1,s.height/2)];
[self addChild:label];
}
-(void) callback2:(id)sender
{
NSLog(@"callback 2 called from:%@", sender);
CGSize s = [[CCDirector sharedDirector] winSize];
CCLabelTTF *label = [CCLabelTTF labelWithString:@"callback 2 called" fontName:@"Marker Felt" fontSize:16];
[label setPosition:ccp( s.width/4*2,s.height/2)];
[self addChild:label];
}
-(void) callback3:(id)sender data:(void*)data
{
NSLog(@"callback 3 called from:%@ with data:%x",sender,(unsigned int)data);
CGSize s = [[CCDirector sharedDirector] winSize];
CCLabelTTF *label = [CCLabelTTF labelWithString:@"callback 3 called" fontName:@"Marker Felt" fontSize:16];
[label setPosition:ccp( s.width/4*3,s.height/2)];
[self addChild:label];
}
-(NSString *) title
{
return @"Callbacks: CallFunc and friends";
}
@end
@implementation ActionCallFuncND
-(void) onEnter
{
[super onEnter];
[self centerSprites:1];
id action = [CCSequence actions:
[CCMoveBy actionWithDuration:2 position:ccp(200,0)],
[CCCallFuncND actionWithTarget:grossini selector:@selector(removeFromParentAndCleanup:) data:(void*)YES],
nil];
[grossini runAction:action];
}
-(NSString *) title
{
return @"CallFuncND + auto remove";
}
-(NSString *) subtitle
{
return @"CallFuncND + removeFromParentAndCleanup. Grossini dissapears in 2s";
}
@end
@implementation ActionCallBlock
-(void) onEnter
{
[super onEnter];
[self centerSprites:1];
id action = [CCSequence actions:
[CCMoveBy actionWithDuration:2 position:ccp(200,0)],
[CCCallBlockN actionWithBlock:
^(CCNode *node){
CCLOG(@"block called");
[node removeFromParentAndCleanup:YES];
} ],
nil ];
[grossini runAction:action];
}