2

コンパイラはエラーを表示しませんが、表示される画面はいくぶん空です。次のコード行でも影響はありません。

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
4

1 に答える 1

3

この行が問題になる可能性があると思います。

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

そしてあるべきです

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

空の SKScene だけの GameScene のインスタンスを作成していませんでした。

それが役立つことを願っています。

于 2015-02-15T03:21:15.123 に答える