首先尝试并咬住这一个......
我有一个ViewController,我想在其视图中显示SKScene 我已经尝试了我能想到的一切,但它没有显示
//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
答案 0 :(得分:1)
错过了正确配置场景......
// Create and configure the scene.
HelloScene *theScene = [HelloScene sceneWithSize:spriteView.bounds.size];
theScene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[spriteView presentScene:theScene
];
希望它有助于其他人