0

I'm having a hard time figuring this out. I'm creating a multiplayer game using the Google Play Games Service API. I want to draw a line on the opponent's screen. Therefore, need to broadcast MotionEvents. Only one player at a time is allowed to do so. So if the player, who is allowed to broadcast, swipes his finger across the screen, i need to send all the MotionEvents (ACTION_DOWN, ACTION_MOVE, ... , ACTION_MOVE, ACTION_UP) to the other opponents. Those opponents need to receive those MotionEvents in the exact same order.

At the moment, i'm broadcasting the MotionEvent right in the moment, when the onTouch()-Method is called. I have to use sendReliableMessage, because it must be guaranteed that all the MotionEvents will be received.

I've attached two additional bytes to the message, which identifies the position of a MotionEvent in the received list of MotionEvents. One message contains 11 bytes: x-coordinate (4 bytes, float), y-coordinate (4 bytes, float), MotionEvent.Action (1 byte, byte), positionIdentifier (2 bytes, short).

This works, but the latency is very high. One can notice the high latency, because the line drawing looks very unsmooth.

I think it might be because i am sending a lot of packages in a short period of time, but if i wrap many MotionEvents into on bigger package, the line drawing would not look smooth, either.

Do you guys have any tips on how i could make this line drawing process look smooth, and not laggy? That would be great.

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
MarcWho
  • 196
  • 2
  • 11
  • Have you tried to queue received messages as you receive them and dequeue them when you are drawing? – Nikola Despotoski Oct 18 '15 at 13:39
  • I thought about that approach, too. But i think if i have stored all the received messages, and then draw the line, the opponent won't see the "drawing process". The line will just appear on screen. I could animate the line drawing process somehow, but this would also not be the same. – MarcWho Oct 18 '15 at 14:18
  • I think about sending the packages via UDP and track the completeness of the received list of packages on the receiving device. If packages are missing, the receiver would need to tell the sender to send the missing packages again. I don't really know if thats too complicated or even if it would bring the wished result. – MarcWho Oct 18 '15 at 15:01
  • Not draw it when all messages come, but queue them and draw them as they come in the queue. – Nikola Despotoski Oct 18 '15 at 20:05

0 Answers0