Google-Play-Services: Creating custom waiting room UI

故事扮演 提交于 2020-02-14 13:22:50

问题


I am about to implement a real-time-multiplayer for my android application with the google play games services and got some problems to listen to room updates. Iam not that experienced, so please forgive the possible understanding problems.

My intention is that I need to get informed, if anybody has joined my recently created room or created another room himself with the same variant as my room.

I have tried to listen on the RoomStatusUpdateListener, but after I created a room, this listener never get called and I wonder why. What does get called, is the RoomUpdateListener, but it contains not the callback methods which I need.

I know that it is recommended to use the android build in waiting room ui and to use Games.RealTimeMultiplayer.getWaitingRoomIntent() to start an activityForResult, but I need to create something like my own waiting room and do not know how. Apparently the google activity (the waiting) room does get informed about changes, so there must be a way to observe these.

As far as I can tell, Iam trying to do something like:

  1. creating multiple rooms with different variants
  2. listen on any room for updates (a player joins or created the same room)
  3. join the room with the update from step 2.

Does anybody have an idea how I can achieve that? I would be so glad. Sorry for my bad english.

Greetings , Steve.


回答1:


Since nobody was able to answer my question or whatever, I think it is valid to provide my result of investigation as an answer myself.

I was able to find the important method calls, which are needed for a custom UI implementation. They are basically located in the two interfaces RoomUpdateListener and RoomStatusUpdateListener and need to be provided to the RoomConfig.Builder.

The lifecycle of a game is like the following:

Step 1

  • create the room via

Games.RealTimeMultiplayer.create(mGoogleApiClient, rtmConfigBuilder.build());

Step 2

  • RoomUpdateListener: onRoomCreated The client attempts to create a real-time room.

Step 3

  • RoomStatusUpdateListener: onPeerJoined Called when one or more peer participants join a room.
  • RoomStatusUpdateListener: onRoomConnecting One or more participants have joined the room and have started the process of establishing peer connections
  • RoomStatusUpdateListener: onP2PConnected Client is successfully connected to a peer participant.
  • RoomStatusUpdateListener: onConnectedToRoom The client is connected to the connected set in a room.
  • RoomStatusUpdateListener: onPeersConnected Called when one or more peer participants join a room.

Step 4

  • RoomUpdateListener: onRoomConnected All the participants in a real-time room are fully connected.

That's it. Now the participants are connected and can send messages via Games.RealTimeMultiplayer.sendReliableMessage and the other send methods.



来源:https://stackoverflow.com/questions/26511788/google-play-services-creating-custom-waiting-room-ui

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