Skip to content

Instantly share code, notes, and snippets.

@mzsima
Created October 16, 2017 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzsima/32a4b396d7d1fb8c1b890db8bdad76ce to your computer and use it in GitHub Desktop.
Save mzsima/32a4b396d7d1fb8c1b890db8bdad76ce to your computer and use it in GitHub Desktop.
four square
//
// 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
@mzsima
Copy link
Author

mzsima commented Oct 16, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment