1

次の問題に苦労しています:

SpriteKitでゲームを作りました。をゲームに実装しGameCenterました。できます。プレイヤーは自動的にログインし、ハイスコアがデフォルトのリーダーボードに追加されます。しかし、たとえば「EndScreen」では、GameCenterLeaderboard.

Appledocumentation は、次のコードを使用する必要があることを教えてくれます。

- (void) showGameCenter

{

GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];

if (gameCenterController != nil)

{

gameCenterController.gameCenterDelegate = self;

[self presentViewController: gameCenterController animated: YES completion:nil];

}

}

しかし、うまくいきpresentViewControllerません。SKSceneaから私の標準に切り替える方法はありますかViewControllerGameCenterleaderboardまたは、ボタンに触れた状態でを表示するにはどうすればよいですか?

正直なところ、私はプログラミングにかなり慣れていないので、ここでのこの問題は、皆さんにとって解決する大きな問題ではないかもしれません. 助けてくれてありがとう。

4

2 に答える 2

3

はい、方法があります。このコードを から直接呼び出すことができます-(void)showGameCenter

  UIViewController *vc = self.view.window.rootViewController;
  [vc presentViewController: gameCenterController animated:YES completion:Nil];
于 2014-04-15T08:01:23.227 に答える
0

通知を使用してViewController、リーダーボードを表示するように指示できます。

ViewController.m:

@implementation GameSceneViewController

- (void)awakeFromNib {
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(showGameCenter)
                                                 name:@"ShowLeaderboard"
                                               object:nil];
}

- (void) dealloc
{
    // If you don't remove yourself as an observer, the Notification Center
    // will continue to try and send notification objects to the deallocated
    // object.
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

.....

SKScene.m:

- (void)showLeaderboard {    
        [[NSNotificationCenter defaultCenter] 
             postNotificationName:@"ShowLeaderboard"
                           object:nil
                         userInfo:nil];
}
于 2014-04-15T08:01:30.393 に答える