first try and bit stuck on this one...
I Have a ViewController that I wish to display an SKScene in its view I've tried everything I can think of but its not showing
- add SpriteKit/SpriteKit.h
- Main.storyboard has a single view controller (myViewController).
- myViewController's view - change class to be SKView. (see pic below)
- Viewdidload
- link to SKScene I wish to load (HelloScene) #import "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
Above:Selecting the view controller’s view object and change its class to SKView