SKView不显示?

时间:2015-02-15 01:20:55

标签: objective-c sprite-kit skview

编译器不会出现任何错误,但显示的屏幕有点空,即使以下代码行也不会影响它:

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

1 个答案:

答案 0 :(得分:3)

我认为这一行可能是个问题。

SKScene * scene = [SKScene sceneWithSize:skView.bounds.size];

应该是

GameScene * scene = [GameScene sceneWithSize:skView.bounds.size];

你没有创建一个GameScene实例只是一个空的SKScene。

我希望有所帮助。