Guest User

Untitled

a guest
Oct 16th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. //
  2. // ViewController.m
  3. // FourSquare
  4. //
  5. // Created by MizushimaYusuke on 2017/10/16.
  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 createPanels];
  22. }
  23.  
  24. - (void)setupScene {
  25. SKView *sv = [[SKView alloc] initWithFrame:self.view.bounds];
  26. SKScene *s = [SKScene sceneWithSize:sv.frame.size];
  27. [sv presentScene:s];
  28. s.backgroundColor = [UIColor yellowColor];
  29.  
  30. [self.view addSubview:sv];
  31. self.scene = s;
  32. }
  33.  
  34. - (void)createPanels {
  35. float l = 60;
  36. for (int i=0; i<10; i++) {
  37. for (int j=0; j<6; j++) {
  38. SKNode *node = [self createMarkPanel];
  39. node.name = [NSString stringWithFormat:@"%d", i + (j % 2)];
  40. node.position = CGPointMake(i * l + l, j * l + l * 0.5);
  41. [self.scene addChild:node];
  42. }
  43. }
  44. }
  45.  
  46. - (SKNode *)createMarkPanel {
  47. float l = 20;
  48. SKNode *panel = [SKNode node];
  49. for (int i=0; i<4; i++) {
  50. SKSpriteNode *box = [SKSpriteNode spriteNodeWithColor:[UIColor blackColor] size:CGSizeMake(l*0.5, l*0.5)];
  51. box.position = CGPointMake((i % 2) * l, (i / 2) * l);
  52. [panel addChild:box];
  53. }
  54. return panel;
  55. }
  56.  
  57. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  58. for (SKNode *node in self.scene.children) {
  59. int n = node.name.length > 0 ? [node.name intValue] : 0;
  60. if (n % 2 == 1) {
  61. [node.children enumerateObjectsUsingBlock:^(SKNode * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  62. [obj runAction:[SKAction rotateByAngle:M_PI * 0.25 duration:0.5]];
  63. }];
  64. }
  65.  
  66. }
  67. }
  68.  
  69. @end
Add Comment
Please, Sign In to add comment