Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // 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
Add Comment
Please, Sign In to add comment