Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. //
  2. // ViewController.m
  3. // SpreadCard
  4. //
  5. // Created by MizushimaYusuke on 2017/03/26.
  6. // Copyright © 2017 MizushimaYusuke. All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10. @import SpriteKit;
  11.  
  12. @interface ViewController ()
  13. @property (nonatomic, weak) SKScene *scene;
  14. @end
  15.  
  16. @implementation ViewController
  17.  
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. [self setupScene];
  21. [self createCardPattern];
  22. }
  23.  
  24. - (void)setupScene {
  25. SKView *sv = [[SKView alloc] initWithFrame:self.view.bounds];
  26. SKScene *s = [SKScene sceneWithSize:sv.frame.size];
  27. s.backgroundColor = [UIColor colorWithHue:0 saturation:1 brightness:0.8 alpha:1];
  28. [sv presentScene:s];
  29. [self.view addSubview:sv];
  30. self.scene = s;
  31. }
  32.  
  33. - (void)createCardPattern {
  34. float dx = CGRectGetMaxX(self.view.bounds) / 6.0;
  35. for (int i=0; i<6; i++) {
  36. for (int j=0; j<10; j++) {
  37. float x = dx * (i + 0.5);
  38. float y = dx * (j + 0.5);
  39. SKNode *c = [self createCard];
  40. c.position = CGPointMake(x, y);
  41. }
  42. }
  43. }
  44.  
  45. - (SKNode *)createCard {
  46. SKNode *node = [SKNode node];
  47. int num = arc4random_uniform(5);
  48.  
  49. for (int i=0; i<8; i++) {
  50. UIColor *color = num == i ? [UIColor blackColor] : [UIColor whiteColor];
  51. SKSpriteNode *card = [SKSpriteNode spriteNodeWithColor:color size:CGSizeMake(40, 25)];
  52. card.anchorPoint = CGPointMake(-0.2, 0.5);
  53. [node addChild:card];
  54.  
  55. [card runAction:[SKAction repeatActionForever:
  56. [SKAction sequence:
  57. @[[SKAction rotateByAngle:i * M_PI / 4.0 duration:1.0],
  58. [SKAction waitForDuration:1.0],
  59. [SKAction rotateByAngle:-i * M_PI / 4.0 duration:1.0]
  60. ]]]];
  61. }
  62. [self.scene addChild:node];
  63. return node;
  64. }
  65.  
  66. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement