1
的第一次嘗試,並停留在這一個有點...視圖控制器與Skview - SpriteKit SKScene
我有,我想在它看來 以顯示SKScene我用盡了一切我能想到的,但一個視圖控制器其未示出
- 添加SpriteKit/SpriteKit.h
- Main.storyboard具有單個視圖控制器(myViewController)。
- myViewController的視圖 - 將類更改爲SKView。 (見下圖)
- viewDidLoad中
- 鏈接SKScene我要加載(HelloScene)#進口 「HelloScene.h」
//ViewController.m
#import "myViewController.h"
#import <SpriteKit/SpriteKit.h>
#import "HelloScene.h"
@interface myViewController()
@end
@implementation myViewController
- (void)viewDidLoad
{
[super viewDidLoad];
SKView *spriteView = (SKView *) self.view;
spriteView.showsDrawCount = YES;
spriteView.showsNodeCount = YES;
spriteView.showsFPS = YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
HelloScene.h
#import <SpriteKit/SpriteKit.h>
@interface HelloScene : SKScene
@end
HelloScene.m
#import "HelloScene.h"
@interface HelloScene()
@property BOOL contentCreated;
@end
@implementation HelloScene
- (void)didMoveToView: (SKView *) view
{
[self LoadSceneContents];
}
- (void)LoadSceneContents
{
self.backgroundColor = [SKColor blueColor];
self.scaleMode = SKSceneScaleModeAspectFit;
[self addChild: [self newHelloNode]];
}
- (SKLabelNode *)newHelloNode
{
SKLabelNode *helloNode = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
helloNode.text = @"Hello, World!";
helloNode.fontSize = 42;
helloNode.position = CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame));
return helloNode;
}
@end
上圖:選擇視圖控制器的視圖對象並改變其類SKView