COCOS2D with Opengl coverflow


/ Published in: iPhone
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #import "HelloWorldScene.h"
  2. #import "MenuScene.h"
  3. #import "Common.h"
  4. #import "GameScene.h"
  5.  
  6. UIWindow *flowCoverWindow;
  7. UIView *flowCoverView;
  8.  
  9. NSString *currentImage;
  10. NSString *previousImage;
  11.  
  12. #define kImageTag 0x01
  13.  
  14. @implementation FlowCoverViewController
  15. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  16. {
  17. return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
  18. (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
  19. }
  20. - (int)flowCoverNumberImages:(FlowCoverView *)view
  21. {
  22. return 6;
  23. }
  24. - (IBAction)done:(id)sender
  25. {
  26. NSLog(@"done");
  27.  
  28. [[self parentViewController] dismissModalViewControllerAnimated:YES];
  29. [[Director sharedDirector] resume];
  30. }
  31. - (UIImage *)flowCover:(FlowCoverView *)view cover:(int)image
  32. {
  33. switch (image) {
  34. case 0:
  35. default:
  36.  
  37. return [UIImage imageNamed:@"dButton1.png"];
  38. case 1:
  39. return [UIImage imageNamed:@"dButton2.png"];
  40. case 2:
  41. return [UIImage imageNamed:@"dButton3.png"];
  42. case 3:
  43. return [UIImage imageNamed:@"dButton4.png"];
  44. case 4:
  45. return [UIImage imageNamed:@"dButton5.png"];
  46. case 5:
  47. return [UIImage imageNamed:@"dButton6.png"];
  48.  
  49. }
  50. }
  51.  
  52. - (void)flowCover:(FlowCoverView *)view didSelect:(int)image
  53. {
  54. NSLog(@"Selected Index %d",image);
  55.  
  56. [[self parentViewController] dismissModalViewControllerAnimated:YES];
  57. [[Director sharedDirector] resume];
  58. [[[Director sharedDirector] openGLView] removeFromSuperview];
  59.  
  60. currentTerrain = image;
  61.  
  62. Scene *s2 = [Scene node];
  63. [s2 addChild: [LevelSelectionLayer node]];
  64. [[Director sharedDirector] replaceScene: s2];
  65.  
  66. }
  67.  
  68. @end
  69.  
  70. // HelloWorld implementation
  71. @implementation HelloWorld
  72.  
  73. +(id) scene
  74. {
  75. // 'scene' is an autorelease object.
  76. Scene *scene = [Scene node];
  77.  
  78. // 'layer' is an autorelease object.
  79. HelloWorld *layer = [HelloWorld node];
  80.  
  81. // add layer as a child to scene
  82. [scene addChild: layer];
  83.  
  84. // return the scene
  85. return scene;
  86. }
  87.  
  88. // on "init" you need to initialize your instance
  89. -(id) init
  90. {
  91.  
  92. if( (self=[super init] )) {
  93.  
  94. }
  95.  
  96. [self ShowCoverFlow];
  97. currentImage = @"icon.png";
  98. previousImage = @"f";
  99. testImage = [Sprite spriteWithFile:currentImage ];
  100.  
  101. [testImage setPosition:ccp(60,70)];
  102. //[self addChild:testImage z:1 tag:kImageTag];
  103. [self schedule: @selector(UpdateImage:) interval:1/60.0f];
  104. [self MoveImage];
  105. return self;
  106.  
  107. }
  108. -(void)MoveImage {
  109.  
  110. id moveSpriteCW = [RotateBy actionWithDuration:3 angle:360];
  111. id moveSpriteCCW = [RotateBy actionWithDuration:1 angle:180];
  112. id seq1 = [Sequence actions: moveSpriteCW, moveSpriteCCW, nil];
  113. id seq2 = [seq1 reverse];
  114. [testImage runAction: [Sequence actions: seq1, seq2, nil]];
  115.  
  116. }
  117. -(void)UpdateImage:(id) sender{
  118. NSLog(@"currentImage is = %@", currentImage);
  119.  
  120. }
  121. -(void) ShowCoverFlow
  122. {
  123.  
  124. UINavigationController *testViewController;
  125. FlowCoverViewController *flowCover;
  126. flowCoverView = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
  127.  
  128. //using a navigation controller to present FlowCover without it rotating to portrait
  129. testViewController = [[UINavigationController alloc] init];
  130.  
  131. //The navigation controller will try to put a nav bar in the window, so we hide it
  132. [testViewController setNavigationBarHidden:YES animated:NO];
  133.  
  134. [testViewController setView:flowCoverView];
  135.  
  136. NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"TestFC" owner:self options:nil];
  137. flowCover = [array objectAtIndex:0];
  138.  
  139. testViewController.delegate = self;
  140. [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
  141. [[[Director sharedDirector] openGLView] addSubview:flowCoverView];
  142. [[Director sharedDirector] pause];
  143. [testViewController presentModalViewController:flowCover animated:YES];
  144.  
  145. }
  146.  
  147. // on "dealloc" you need to release all your retained objects
  148. - (void) dealloc
  149. {
  150.  
  151. [super dealloc];
  152. }
  153. @end

URL: http://www.cocos2d-iphone.org/forum/topic/6653

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.