终于让我的领导人登上了,但得分没有出现

时间:2012-07-21 14:36:40

标签: ios objective-c cocos2d-iphone

我终于让我的排行榜出现了。现在我只需要实现我的分数会弹出。
我的分数在NSString NSUserDefaults下保存为score,名称为#import <UIKit/UIKit.h> #import <GameKit/GameKit.h> #import "GameCenterManager.h" @class GameCenterManager; @interface Game_CenterViewController : UIViewController <UIActionSheetDelegate, GKLeaderboardViewControllerDelegate, GKAchievementViewControllerDelegate, GameCenterManagerDelegate> { GameCenterManager *gameCenterManager; int64_t currentScore; NSString *currentLeaderBoard; } @property (nonatomic, retain) GameCenterManager *gameCenterManager; @property (nonatomic, assign) int64_t currentScore; @property (nonatomic, retain) NSString* currentLeaderBoard; @end

以下是一些代码:

Game_CenterViewController.h

#import "Game_CenterViewController.h"
#import "AppSpecificValues.h"
#import "GameCenterManager.h"

@implementation Game_CenterViewController
@synthesize gameCenterManager;
@synthesize currentScore;
@synthesize currentLeaderBoard;

- (void)dealloc {
    [gameCenterManager release];
    [currentLeaderBoard release];
    [currentScoreLabel release];
    [super dealloc];
}

#pragma mark - View lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];
    self.currentLeaderBoard = thescore101;
    self.currentScore = score    
    if ([GameCenterManager isGameCenterAvailable]) {
        self.gameCenterManager = [[[GameCenterManager alloc] init] autorelease];
        [self.gameCenterManager setDelegate:self];
        [self.gameCenterManager authenticateLocalUser];
    } else {
        // The current device does not support Game Center.
    }
}

- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController {
    [self dismissModalViewControllerAnimated: YES];
    [viewController release];
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.gameCenterManager = nil;
    self.currentLeaderBoard = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

Game_CenterViewController.m

NSString

目前的分数是我试图将{{1}}放入的地方。

1 个答案:

答案 0 :(得分:0)

已编辑:我认为在当前的分数中使用int会更好。

这是你在找什么?

- (void)submitMyScore:(int64_t)score
{

    GKScore *myScoreValue = [[[GKScore alloc] initWithCategory:@"yourCat"] autorelease];
    myScoreValue.value = (int)score;

    [myScoreValue reportScoreWithCompletionHandler:^(NSError *error){
        if(error != nil){
            NSLog(@"Score Submission Failed");
        } else {
            NSLog(@"Score Submitted: %d",(int)score);
        }

    }];
}

所以你应该添加一个IBAction

- (IBAction)buttonPressed
{
    [self submitMyScore:currentScore];
}

通过这个并将SEND MY SCORE按钮连接到此IBAction,您将提交您的分数。

我希望这对你有用。