Hey,
im working on adding Network support to my game. on 127.0.0.1 it runs fine. If i try with a Friend over the internet we get really bad gaming Performance.
this code is sending the moving Blocks in our world to the Clients :
this is the sendObjecttoall clients method :
But as mentioned we get really bad Performance. (with bad Performance i mean moving Boxes constanly warping for the Client, but only for few Pixels, increasing if the moving speed of the Boxes Increases)
And it also lags for the client, increasing if he moves faster.
Why is that ? And how can i fix that ?
thanks in advance. Greetings
EDIT
i forgot to mention i use the AsyncNetwork.framework
im working on adding Network support to my game. on 127.0.0.1 it runs fine. If i try with a Friend over the internet we get really bad gaming Performance.
this code is sending the moving Blocks in our world to the Clients :
-(void)didSimulatePhysics {
// center camera on player
_camera.position = _playerSprite.position;
[self centerOnNode: [self childNodeWithName: @"//camera"]];
// send all non resting Body Positions over the TriggerPoint to all clients
float static triggerPoint = 0.000;
for (Block *block in _world.children) {
if ([block isKindOfClass:[Block class]] && !block.physicsBody.isResting && (block.physicsBody.velocity.dx > triggerPoint || block.physicsBody.velocity.dy > triggerPoint || block.physicsBody.velocity.dx < triggerPoint || block.physicsBody.velocity.dy < triggerPoint)) {
BlockPosition *pos = [[BlockPosition alloc]initWithUUID:block.uuid.UUIDString Position:block.position Rotation:block.zRotation];
// UDP
[_gameServer sendObjectToAllClients_UDP: pos];
}
}
this is the sendObjecttoall clients method :
-(void)sendObjectToAllClients_UDP: (id)obj{
// Encode Object to NSData
NSData *encodedPos = [NSKeyedArchiver archivedDataWithRootObject: obj];
// send Data to all connected Clients
for (AsyncConnection *con in self.server.connections) {
[self.broadcaster.broadcastSocket sendData:encodedPos toHost:con.host port:40001 withTimeout:-1.0 tag:0];
NSLog([NSString stringWithFormat"server sending UDP msg to: %@:%lu", con.host, con.port]);
}
But as mentioned we get really bad Performance. (with bad Performance i mean moving Boxes constanly warping for the Client, but only for few Pixels, increasing if the moving speed of the Boxes Increases)
And it also lags for the client, increasing if he moves faster.
Why is that ? And how can i fix that ?
thanks in advance. Greetings
EDIT
i forgot to mention i use the AsyncNetwork.framework
Last edited: