//
// 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_SpriteKit_01_初识SpriteKit
最新推荐文章于 2024-05-15 09:34:59 发布