首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SKView不显示吗?

SKView不显示吗?
EN

Stack Overflow用户
提问于 2015-02-15 09:20:55
回答 1查看 128关注 0票数 2

编译器不会给出任何错误,但出现的屏幕有点空,甚至下面这行代码也不会影响它:

代码语言:javascript
复制
self.backgroundColor = [SKColor colorWithRed:0.0 green:0.0 blue:0.5 alpha:0.0];

我试图将我的代码与视图控制器和场景文件的其他模板代码进行比较,但没有成功地发现问题所在。我使用的是Xcode6,代码如下:1)场景文件

代码语言:javascript
复制
#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)查看控制器文件

代码语言:javascript
复制
#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
EN

回答 1

Stack Overflow用户

发布于 2015-02-15 11:21:15

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

代码语言:javascript
复制
SKScene * scene = [SKScene sceneWithSize:skView.bounds.size];

而且应该是

代码语言:javascript
复制
GameScene * scene = [GameScene sceneWithSize:skView.bounds.size];

您创建的不是GameScene的实例,而是一个空的SKScene。

我希望这能有所帮助。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28522124

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档