GoogleApi Real Time Multiplayer pushing updates

我只是一个虾纸丫 提交于 2019-12-25 09:05:47

问题


i am using the Google Api to create a Real Time Multiplayer - Top down shooter game with libGDX.

Player positions are send over "sendUnreliableMessage" on every call of the "render()" method :

  • render() called.
  • "Device A" sends the local Player position (x, y) and the moving direction over "sendUnreliableMessage".
  • "Device B" recieves the message. Interpolates between the last position (x,y) and the new position (x,y).
  • "Device B" moves the local enemy Player to the new positions. (Interpolated and final position)

The bullets shot by the players are send over "sendReliableMessage" like this :

  • Player presses the "fire" button.
  • Bullet object is created on the local "Device A" and starts flying.
  • Bullet creation position (x, y) and the direction are send by "sendReliableMessage" to the other player.
  • "Device B" recieves the message and also creates a Bullet Object locally on the recieved starting x and y, and makes it fly in the recieved direction.

The movement messages are send on each "render()" call. -Depending on the FPS around 30-60 times a second.

The bullet messages are send only when the "fire" button is pressed. Only once. And only the "creation position" of the bullet. Both Devices calculate updates on movement locally from this position.

My Problem and Questions are :

  • Updating the Player position like this is way to often right ?
  • Shots are getting lost. 1-3 of 4. Which is around 50-80% package loss.

I tested only sending updates of the Player Position on movement. Then shot 4 times while standing still ( no "player position 'unreliableMessages' were send) and all 4 shots appeared on "Device B"

Which makes me think that "reliableMessages" are getting lost when i send "unreliableMessages" on every frame update ( again around 30-60 times a second ).


回答1:


If we rely purely with Sending game data, the way I understand it, you can implement sending data messages using the two messaging protocols provided by Google Play games services.

To answer your questions:

1. Updating the Player position like this is way to often right ?

You may still opt to use either of the two given messaging protocols. Just choose which suits you best, however, please note that your app is responsible for ensuring that the game behaves correctly if messages are dropped in transmission or received out of order.

2. Shots are getting lost. 1-3 of 4. Which is around 50-80% package loss.

With reliable messaging, data delivery, integrity, and ordering are guaranteed. You can choose to be notified of the delivery status by using a callback. But, to avoid losing some updates, please also note that there's a maximum size of messages that you can send for both reliable or unreliable messages.

In addition to what was given in the documentation, suggestion in this SO post - Real Time Multiplayer Best way for pushing updates on android might also help.



来源:https://stackoverflow.com/questions/39425593/googleapi-real-time-multiplayer-pushing-updates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!