简体   繁体   English

Box2D和GameCenter多人游戏

[英]Box2D and GameCenter multiplayer

i have a hockey game with mallets running on iphone/ipad. 我有一个曲棍球游戏,在iPhone / iPad上运行槌槌。 The server controlls all the physics and send to the other device the server mallet position and the client sends to the server his mallet position. 服务器控制所有物理并将服务器槌位置发送到另一设备,客户端将他的槌位置发送到服务器。

This part is working properly, the problem is about the puck. 这部分工作正常,问题出在冰球上。 Becuase is way too fast and the server is the onde whos sending the message. 因为速度太快,服务器是由谁来发送消息。 The problem is that the puck is a b2_dynamic body and the server sends to the client where puck is at. 问题在于,圆盘是一个b2_dynamic实体,服务器将其发送到圆盘所在的客户端。 I have updated to send the position to the client every frame on gameLoop, but the problem is thats not flowing properly. 我已经更新了位置,以将gameLoop上的每一帧发送给客户端,但是问题是那没有正确地进行。 The mallets movements are ok, but with the puck its wierd a bit, i think it has to due with the linear velocity of the puck. 槌的运动还可以,但是随着冰球的变化,我认为这必须归因于冰球的线速度。

What im doing is this: 我在做什么是这样的:

[gamedelegate movePuckToX:messageData->x andY:messageData->y andAngle:0.0];


- (void) sendMovePuck {
MessageMovePuckTo message;
message.message.messageType = kMessageTypeMovePuck;

float_t pX = puck->GetPosition().x;
float_t pY = puck->GetPosition().y;

message.x = pX;
message.y = pY;

NSData *data = [NSData dataWithBytes:&message length:sizeof(MessageMovePuckTo)];    
[self sendData:data];    
}


-(void )movePuckToX:(float_t)x andY:(float_t)y  andAngle:(float_t)ang
{
    lastPuckReceivedPosition = b2Vec2(x, [self getScreenSize].height/32 - y);
    puck->SetAwake(false);        
    puck->SetTransform(b2Vec2(x, [self getScreenSize].height/32 - y), 0);           
    puck->SetLinearVelocity(b2Vec2(0,0));
}

Whats the best of sending the puck position to the client? 将冰球位置发送给客户的最佳方法是什么? Any ideas or insights? 有什么想法或见解吗? I cant managed to solve this :( 我无法解决这个问题:(

You should try using dead reckoning and calculate it on each side. 您应该尝试使用航位推测法并在每一侧进行计算。 Use the host just to distribute last play. 仅使用主持人来分发最后一场比赛。

In navigation, dead reckoning is the process of calculating one's current position by using a previously determined position, or fix, and advancing that position based upon known or estimated speeds over elapsed time, and course. 在导航中,航位推算是通过使用先前确定的位置或定位来计算一个人的当前位置,并根据经过或经过的时间和航向的已知或估计速度来推进该位置的过程。

http://en.wikipedia.org/wiki/Dead_reckoning http://en.wikipedia.org/wiki/Dead_reckoning

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM