编译器没有给出任何错误,但出现的屏幕有些空,即使下面这行代码也不会影响它:
self.backgroundColor = [SKColor colorWithRed:0.0 green:0.0 blue:0.5 alpha:0.0];
我尝试将我的代码与 View Controller 和场景文件的其他模板代码进行比较,但没有成功找到问题所在。我使用的是 Xcode 6。以下是代码:1) 场景文件
#import "GameScene.h"
#import "Ball.h"
#import "WorldGenerator.h"
// 1
@interface GameScene ()
@property BOOL isStarted;
@end
@implementation GameScene
{
Ball *ball;
SKNode *world;
WorldGenerator *generator;
}
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
//setup your scene here
self.anchorPoint = CGPointMake(0.5, 0.5);
self.backgroundColor = [SKColor colorWithRed:0.0 green:0.0 blue:0.5 alpha:0.0];
//World
world = [SKNode node];
[self addChild:world];
generator = [WorldGenerator generatorWithWorld:world];
[self addChild:generator];
[generator populate];
// Ball allocation
ball = [Ball ball];
[self addChild:ball];
}
return self;
}
2)查看 Controller 文件
#import "GameViewController.h"
#import "GameScene.h"
@implementation GameViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Create and configure the scene.
SKScene * scene = [SKScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
- (BOOL)shouldAutorotate{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return UIInterfaceOrientationMaskAllButUpsideDown;
} else {
return UIInterfaceOrientationMaskAll;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
@end
最佳答案
我认为这条线可能是问题所在。
SKScene * scene = [SKScene sceneWithSize:skView.bounds.size];
应该是
GameScene * scene = [GameScene sceneWithSize:skView.bounds.size];
您没有创建 GameScene 实例,而只是创建一个空的 SKScene。
希望对您有所帮助。
关于objective-c - SKView不显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28522124/