Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.m
- // SpreadCard
- //
- // Created by MizushimaYusuke on 2017/03/26.
- // 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 createCardPattern];
- }
- - (void)setupScene {
- SKView *sv = [[SKView alloc] initWithFrame:self.view.bounds];
- SKScene *s = [SKScene sceneWithSize:sv.frame.size];
- s.backgroundColor = [UIColor colorWithHue:0 saturation:1 brightness:0.8 alpha:1];
- [sv presentScene:s];
- [self.view addSubview:sv];
- self.scene = s;
- }
- - (void)createCardPattern {
- float dx = CGRectGetMaxX(self.view.bounds) / 6.0;
- for (int i=0; i<6; i++) {
- for (int j=0; j<10; j++) {
- float x = dx * (i + 0.5);
- float y = dx * (j + 0.5);
- SKNode *c = [self createCard];
- c.position = CGPointMake(x, y);
- }
- }
- }
- - (SKNode *)createCard {
- SKNode *node = [SKNode node];
- int num = arc4random_uniform(5);
- for (int i=0; i<8; i++) {
- UIColor *color = num == i ? [UIColor blackColor] : [UIColor whiteColor];
- SKSpriteNode *card = [SKSpriteNode spriteNodeWithColor:color size:CGSizeMake(40, 25)];
- card.anchorPoint = CGPointMake(-0.2, 0.5);
- [node addChild:card];
- [card runAction:[SKAction repeatActionForever:
- [SKAction sequence:
- @[[SKAction rotateByAngle:i * M_PI / 4.0 duration:1.0],
- [SKAction waitForDuration:1.0],
- [SKAction rotateByAngle:-i * M_PI / 4.0 duration:1.0]
- ]]]];
- }
- [self.scene addChild:node];
- return node;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement