我试图向float我的游戏中心排行榜提交两位小数长度,但是唯一允许提交的格式是int64_t.我使用默认的Apple报告分数方法:
- (void)reportScore:(int64_t)score forCategory:(NSString *)category {
GKScore *scoreReporter = [[GKScore alloc] initWithCategory:category];
scoreReporter.value = score;
[scoreReporter reportScoreWithCompletionHandler: ^(NSError *error) {
[self callDelegateOnMainThread: @selector(scoreReported:) withArg: NULL error: error];
}];
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用此方法为报表分数方法提供分数:
- (IBAction)increaseScore {
self.currentScore = self.currentScore + 1;
currentScoreLabel.text = [NSString stringWithFormat: @"%lld", self.currentScore];
NSLog(@"%lld", self.currentScore);
}
Run Code Online (Sandbox Code Playgroud)
请帮忙,我一直在谷歌上搜索疯狂,无法找到答案.
我正在尝试为我的游戏设置排行榜,但我不知道要传递给GKScore:initWithCategory.在Itunes Connect中查看"排行榜参考名称"和"排行榜ID"这两个我已经尝试过,但现在游戏中心仍会显示分数.
在ITC中没有提到"类别",术语是否已更改?我将什么传递给这个功能?
所以我在阅读苹果文档后感到疑惑(https://developer.apple.com/library/ios/documentation/GameKit/Reference/GKLeaderboard_Ref/Reference/Reference.html#//apple_ref/occ/instp/GKLeaderboard/category)如何创建一个UITableView并用localPlayers Game Center朋友填充它,并在特定的排行榜中得分.我知道如何使用loadScoresWithCompletionHandler:方法单独获取好友列表和好友分数.
编辑:到目前为止,我得到了这个以获得个人朋友的照片,得分和显示名称保存到一个NSArray.但我无法弄清楚如何在UITableView中显示它们.
- (void) loadPlayerData: (NSArray *) identifiers
{
GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init];
if (leaderboardRequest != nil) {
leaderboardRequest.playerScope = GKLeaderboardPlayerScopeFriendsOnly;
leaderboardRequest.timeScope = GKLeaderboardTimeScopeAllTime;
leaderboardRequest.category = @"MJ_IL";
[leaderboardRequest loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) {
if (error != nil) {
// handle the error. if (scores != nil)
}
if (scores != nil){
for (GKScore* score in scores) {
NSArray *playerIdArray = [NSArray arrayWithObject:score.playerID];
[GKPlayer loadPlayersForIdentifiers:playerIdArray withCompletionHandler:^(NSArray *players, NSError *error) {
GKPlayer *player = [players …Run Code Online (Sandbox Code Playgroud) 我想将排行榜添加到我的 SwiftUI 应用程序中。
我找不到任何使用 loadEntries 加载排行榜值的示例。我尝试了以下...
let leaderBoard: GKLeaderboard = GKLeaderboard()
leaderBoard.identifier = "YOUR_LEADERBOARD_ID_HERE"
leaderBoard.timeScope = .allTime
leaderBoard.loadScores { (scores, error) in ...
Run Code Online (Sandbox Code Playgroud)
这会导致以下警告:
使用 loadEntriesForPlayerScope 会导致以下警告:
使用loadEntries我不知道如何指定排行榜标识符。
我在cocos2d中总是收到失败,但是当我在基于视图的应用程序中运行此项目时,它会给我成功,并且分数将很容易提交
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error){
if (error ==nil) {
NSLog(@"Success");
} else {
NSLog(@"Fail");
}
}];
GKScore *myScoreValue = [[[GKScore alloc] initWithCategory:@"123"] autorelease];
myScoreValue.value = lastScore;
[myScoreValue reportScoreWithCompletionHandler:^(NSError *error){
if(error != nil){
NSLog(@"Score Submission Failed");
} else {
NSLog(@"Score Submitted");
}
}];
Run Code Online (Sandbox Code Playgroud) 我在我的Cocos2d游戏中使用GameKitHelper.在某些时候,我会想要显示排行榜,所以我这样做:
[[GameKitHelper sharedGameKitHelper] showLeaderboard];
Run Code Online (Sandbox Code Playgroud)
但没有任何反应.我该怎么办?
我已经实现了自动匹配,并在具有不同游戏中心帐户的两个实际设备之间进行了测试,因此我知道我已正确设置该部分:我可以创建匹配,并在两个玩家之间发送数据.现在我正在实施邀请部分.
该游戏中心编程指南 说:
当您的游戏直接从Game Center应用程序启动以主持匹配时,playersToInvite参数为非零.此参数包含一系列玩家标识符,列出要邀请参加比赛的玩家.
我不明白的是,如何通过游戏中心应用程序邀请玩家.在游戏中心应用程序中,我可以看到我的游戏.当我点击它时,在右上角有一个带文字的按钮:"...".当我点击它时,我看到两个选项:"播放"和"分享".点击"播放"即可启动我的应用.
是否有一些我需要实现的代码,Game center app以便向我提供选择朋友邀请等的选项?
编辑:这篇文章中的人似乎与我的问题几乎相同: 对于玩家托管的内容的 确切答案到目前为止还没有明确的答案,关于如何填充这些数据.
gamekit ×7
objective-c ×4
game-center ×3
ios ×3
iphone ×2
gkscore ×1
swiftui ×1
uitableview ×1