iOS_SpriteKit_01_初识SpriteKit

iOS_SpriteKit_01_初识SpriteKit_第1张图片

iOS_SpriteKit_01_初识SpriteKit_第2张图片

iOS_SpriteKit_01_初识SpriteKit_第3张图片



iOS_SpriteKit_01_初识SpriteKit_第4张图片

iOS_SpriteKit_01_初识SpriteKit_第5张图片

iOS_SpriteKit_01_初识SpriteKit_第6张图片

iOS_SpriteKit_01_初识SpriteKit_第7张图片

iOS_SpriteKit_01_初识SpriteKit_第8张图片

iOS_SpriteKit_01_初识SpriteKit_第9张图片

iOS_SpriteKit_01_初识SpriteKit_第10张图片




//
//  GameViewController.m
//  SpriteKit01
//
//  Created by beyond on 15/12/28.
//  Copyright (c) 2015年 beyond. All rights reserved.
//

#import "GameViewController.h"
#import <SpriteKit/SpriteKit.h>

#import "GameScene.h"


// 这个是什么鬼???
@implementation SKScene (Unarchive)

// 分类方法: 根据文件名,从文件中解档 生成场景
+ (instancetype)unarchiveFromFile:(NSString *)file {
    /* Retrieve scene file path from the application bundle */
    NSString *nodePath = [[NSBundle mainBundle] pathForResource:file ofType:@"sks"];
    /* Unarchive the file to an SKScene object */
    NSData *data = [NSData dataWithContentsOfFile:nodePath
                                          options:NSDataReadingMappedIfSafe
                                            error:nil];
    NSKeyedUnarchiver *arch = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
    [arch setClass:self forClassName:@"SKScene"];
    SKScene *scene = [arch decodeObjectForKey:NSKeyedArchiveRootObjectKey];
    [arch finishDecoding];
    
    return scene;
}

@end





@implementation GameViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    // xib里面class类型就是SKView
    SKView * skView = (SKView *)self.view;
    skView.showsFPS = YES;
    skView.showsNodeCount = YES;
    
    /* Sprite Kit applies additional optimizations to improve rendering performance */
    skView.ignoresSiblingOrder = YES;
    
    // 上面的分类方法: 根据文件名,从文件中解档 生成场景
    GameScene *scene = [GameScene unarchiveFromFile:@"GameScene"];
    
    scene.scaleMode = SKSceneScaleModeAspectFill;
    
    // Present the scene.
    [skView presentScene:scene];
}

#pragma mark - 横竖屏
- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    } else {
        return UIInterfaceOrientationMaskAll;
    }
}

#pragma mark - 状态条隐藏
- (BOOL)prefersStatusBarHidden {
    return YES;
}

@end
























你可能感兴趣的:(ios,xcode,SpriteKit)