Created
October 16, 2017 13:03
-
-
Save mzsima/32a4b396d7d1fb8c1b890db8bdad76ce to your computer and use it in GitHub Desktop.
four square
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.m | |
// FourSquare | |
// | |
// Created by MizushimaYusuke on 2017/10/16. | |
// Copyright © 2017 MizushimaYusuke. All rights reserved. | |
// | |
#import "ViewController.h" | |
@import SpriteKit; | |
@interface ViewController () | |
@property (nonatomic, weak) SKScene *scene; | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
[self setupScene]; | |
[self createPanels]; | |
} | |
- (void)setupScene { | |
SKView *sv = [[SKView alloc] initWithFrame:self.view.bounds]; | |
SKScene *s = [SKScene sceneWithSize:sv.frame.size]; | |
[sv presentScene:s]; | |
s.backgroundColor = [UIColor yellowColor]; | |
[self.view addSubview:sv]; | |
self.scene = s; | |
} | |
- (void)createPanels { | |
float l = 60; | |
for (int i=0; i<10; i++) { | |
for (int j=0; j<6; j++) { | |
SKNode *node = [self createMarkPanel]; | |
node.name = [NSString stringWithFormat:@"%d", i + (j % 2)]; | |
node.position = CGPointMake(i * l + l, j * l + l * 0.5); | |
[self.scene addChild:node]; | |
} | |
} | |
} | |
- (SKNode *)createMarkPanel { | |
float l = 20; | |
SKNode *panel = [SKNode node]; | |
for (int i=0; i<4; i++) { | |
SKSpriteNode *box = [SKSpriteNode spriteNodeWithColor:[UIColor blackColor] size:CGSizeMake(l*0.5, l*0.5)]; | |
box.position = CGPointMake((i % 2) * l, (i / 2) * l); | |
[panel addChild:box]; | |
} | |
return panel; | |
} | |
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { | |
for (SKNode *node in self.scene.children) { | |
int n = node.name.length > 0 ? [node.name intValue] : 0; | |
if (n % 2 == 1) { | |
[node.children enumerateObjectsUsingBlock:^(SKNode * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { | |
[obj runAction:[SKAction rotateByAngle:M_PI * 0.25 duration:0.5]]; | |
}]; | |
} | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://lepetit-prince.net/ios/?p=6751