Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to balance start time for a multiplayer game?
    primarykey
    data
    text
    <p>I'm making a multiplayer game with GameKit. My issue is that when two devices are connected the game starts running with a slight time difference. On of the devices starts running the game a bit later. But this is not what i want. i want it to start simultaneously on both devices. So the first thing that i do is i check time of the beginning on both devices like this:</p> <pre><code>startTime = [NSDate timeIntervalSinceReferenceDate]; </code></pre> <p>and this is how it looks:</p> <pre><code>361194394.193559 </code></pre> <p>Then I send <code>startTime</code> value to the other device and then i compare received value with startTime of the other device. </p> <pre><code>- (void)balanceTime:(double)partnerTime { double time_diff = startTime - partnerTime; if (time_diff &lt; 0) startTimeOut = -time_diff; } </code></pre> <p>So if difference between two start times is negative it means that this device is starting earlier and therefore it has to wait for exactly the difference assigned to <code>startTimeOut</code> variable, which is a <code>double</code> and usually is something like <code>2.602417</code>. So then i pause my game in my update method </p> <pre><code>- (void)update:(ccTime)dt { if (startTimeOut &gt; 0) { NSLog(@"START TIME OUT %f", startTimeOut); startTimeOut -= dt; return; } } </code></pre> <p>But it unfortunately it doesn't help. Moreover it even extends the difference between start times of the devices. I just can't get why. Seems like everything i'm doing is reasonable. What am i doing wrong? How do i correct it? What would you do? Thanks a lot</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload