I've created a real time multiplayer game with 2 other players (both directly invited). Here is how I did that:
Created player selection intent
Intent intent = Games.RealTimeMultiplayer.getSelectOpponentsIntent(getApiClient(), 1, MAX_PLAYERS);
startActivityForResult(intent, REQ_GOOGLE_INVITE);
On onActivityResult()
executed this:
private void onPlayersInvited(Intent data) {
// get the invitee list
final ArrayList<String> invitees = data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);
Bundle autoMatchCriteria = RoomConfig.createAutoMatchCriteria(1, 5, 0);
// create the activeRoom and specify a variant if appropriate
RoomConfig.Builder roomConfigBuilder = makeBasicRoomConfigBuilder();
roomConfigBuilder.addPlayersToInvite(invitees);
roomConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
RoomConfig roomConfig = roomConfigBuilder.build();
Games.RealTimeMultiplayer.create(getApiClient(), roomConfig);
// prevent screen from sleeping during handshake
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
private RoomConfig.Builder makeBasicRoomConfigBuilder() {
return RoomConfig.builder(this).setMessageReceivedListener(this).setRoomStatusUpdateListener(this).setSocketCommunicationEnabled(true)
.setVariant(subcategory.getId().intValue());
}
My game starts on all 3 devices, but when I disconnect from the game on one invited device, then on host device onDisconnectedFromRoom() is called, so I guess the game gets canceled automatically, which is sad, because I'd like to continue the game until min required number of players is present.
Is there a way to prevent that?
Weird behaviour was caused by seting AutomatchCryteria. I removed it and now it behaves well