Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios game center submit time and show in leader board

in my app i need to submit the time to the game center and i need to show that in Elapsed Time - To the hundredth of a second format.

00:00:00.00

this is the format i want to show in leader board.

In my app im getting the time in following format

ss.SS

ss = seconds SS = hundredth of a second

i converted the value to double before send it to the game center

double newScoreDouble = [newScore doubleValue];

But when i sending the double score to the game center it asking me to convert it to int64_t format. But when i convert it to that format it loses some part of the double value.

double intPart = 0;
double fractPart = modf(newScoreDouble, &intPart);
int isecs = (int)intPart;
int min = isecs / 60;
int sec = isecs % 60;
int hund = (int) (fractPart * 100);

int64_t time_to_send_through_game_center = min*6000 + (sec*100 + hund);

this is the way i convert double to int64_t

Can any one say how to send whole double value to the game center and display it in Elapsed Time - To the hundredth of a second format.

Thanks

like image 930
Sameera Chathuranga Avatar asked Aug 07 '12 06:08

Sameera Chathuranga


People also ask

How do I enable screen time in Game Center?

To do this on your iOS or iPadOS device, go to Settings > Screen Time > Content & Privacy Restrictions > Content Restrictions. On Mac, go to System Settings > Screen Time > Content & Privacy. On tvOS, go to Settings > General > Restrictions.

How do I manage Game Center on my iPhone?

On your iPhone, iPad, or iPod touchOpen Settings. Scroll to Game Center, then tap it. Tap Friends to see a list of users who you're friends with and users who you've recently played with.


1 Answers

I've done this before. When you're recording a score in the to the hundredth of a second format. You would multiply your seconds with a hundred before submitting.

So let's say the user scored 1minute 44 seconds 300 milliseconds : 1:44:30 = 104.3 seconds. Then you would set your value property of GKScore object equal to 104.3 * 100 = 10430 ,and submit it like that.

Give it a try :)

like image 195
Kaan Dedeoglu Avatar answered Sep 30 '22 19:09

Kaan Dedeoglu