I am developing a 3D bluetooth multiplayer game for iPhone and iPad without using any game engine. I am using GKSession class to send data between devices over Bluetooth using Peer to Peer mode. If I continue to play the game for some time there is no performance drop issue, but when I disconnect (even without exiting the game) and reconnect the game again via Bluetooth game mode, then I am facing the performance drop (game lag) issue.
I tried profiling my code (when the game lags) and found that the data packets require more time (approx. 10 ms) to transfer to the other device which usually takes 2 ms when the game runs without lag.
I have three questions:
I am assuming that the increase in data transfer time can be the cause for the lag issue. If yes, how to fix such issue?
I am testing my game on iPad and iPhone running on iOS 7 and 8 respectively. As GKSession is deprecated with iOS 7, will this affect the game performance?
- Are there any other parts of the code which can cause such performance issue?
I’d appreciate any suggestions on this issue. Thank you in advance.
Code snippets:
Code to disconnect two devices
if(session!=nil)
{
[session disconnectFromAllPeers];
[session setAvailable:NO];
[session setDataReceiveHandler:NULL withContext:NULL];
session.delegate = nil;
[session release];
}
Code to create session
(GKSession *) peerPickerController:(GKPeerPickerController *)picker sessionForConnectionType:(GKPeerPickerConnectionType)type {
session = [[GKSession alloc] initWithSessionID:@"XYZ" displayName:nil sessionMode:GKSessionModePeer]; session.delegate = self; session.available = YES; return session;
}
Definition of session in header file
@property (nonatomic, retain) GKSession *session;