编译器没有给出任何错误,但出现的屏幕有些空白,即使以下代码行也不影响它:
self.backgroundColor = [SKColor colorWithRed:0.0 green:0.0 blue:0.5 alpha:0.0];
我试图将我的代码与视图控制器和场景文件的其他模板代码进行比较,但没有成功找到问题所在。我正在使用 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) 查看控制器文件
#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