Play游戏多人游戏的等候室不显示已连接的玩家

时间:2019-01-25 23:09:20

标签: android google-play-services google-play-games

我在其中一个游戏应用程序中使用了Google Play游戏服务的实时多人支持。这样指定自动匹配配置:

Bundle autoMatchCriteria = RoomConfig.createAutoMatchCriteria(7, 7, 0);

因此它将创建一个有6个玩家的游戏。我现在遇到以下问题:

比方说,已经有4个人连接到候诊室,那么他们将不会见面。因此,他们不知道其他人已经连接。仅当所有7位参与者都已连接时,播放器的名称才会显示。这种行为不会激励人们在所有玩家连接之前一直待在候诊室,因为在他们看来,就像他们一个人在等待一样。

下图显示了等候室。已经连接了两个人,但玩家只能自己看到他们。当房间已满时为时已晚,字符串“ auto-pick”将替换为玩家名称。

Waiting room

如何向玩家显示等候室的真实状态?我不想激励他们留在候诊室。

等级依赖性:

dependencies {
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:mediarouter-v7:28.0.0'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support:customtabs:28.0.0'
implementation 'com.android.billingclient:billing:1.2'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.google.android.gms:play-services-appstate:6.5.87'
implementation 'com.google.android.gms:play-services-games:16.0.0'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.android.gms:play-services-ads:16.0.0'

游戏就是这样创建的:

   void startQuickGame() {
    final int MAX_OPPONENTS = 6;
    int min_opponents = 6;
    Bundle autoMatchCriteria = RoomConfig.createAutoMatchCriteria(min_opponents,
            MAX_OPPONENTS, 0);
    RoomConfig.Builder rtmConfigBuilder = RoomConfig.builder(this);
    rtmConfigBuilder.setMessageReceivedListener(this);
    rtmConfigBuilder.setRoomStatusUpdateListener(this);
    rtmConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
    rtmConfigBuilder.setVariant(variant);
    switchToScreen(R.id.mpGamescreen_wait);
    keepScreenOn();

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

上述方法startQuickGame();onConnected(Bundle connectionHint)方法内部被调用。 onActivityResult看起来像:

    @Override
public void onActivityResult(int requestCode, int responseCode, Intent intent) {
    super.onActivityResult(requestCode, responseCode, intent);

    switch (requestCode) {
        case RC_SELECT_PLAYERS:
            // we got the result from the "select players" UI -- ready to create the room
            handleSelectPlayersResult(responseCode, intent);
            break;
        case RC_WAITING_ROOM:
            // we got the result from the "waiting room" UI.
            if (responseCode == Activity.RESULT_OK) {
                // ready to start playing
                Log.d(TAG, "debug Starting game (waiting room returned OK).");
                //startGameHandler(true);
            } else if (responseCode == GamesActivityResultCodes.RESULT_LEFT_ROOM) {
                // player indicated that they want to leave the room
                leaveRoom();
            } else if (responseCode == Activity.RESULT_CANCELED) {
                // Dialog was cancelled (user pressed back key, for instance). In our game,
                // this means leaving the room too. In more elaborate games, this could mean
                // something else (like minimizing the waiting room UI).
                leaveRoom();
            }
            break;
        case RC_SIGN_IN:
            Log.d(TAG, "debug onActivityResult with requestCode == RC_SIGN_IN, responseCode="
                + responseCode + ", intent=" + intent);
            mSignInClicked = false;
            mResolvingConnectionFailure = false;
            if (responseCode == RESULT_OK) {
              mGoogleApiClient.connect();
            } else {
              BaseGameUtils.showActivityResultError(this,requestCode,responseCode, R.string.signin_other_error);
            }
            break;
    }
    super.onActivityResult(requestCode, responseCode, intent);
}

API客户端是在oncreate中创建的。请注意,不建议使用某些方法(以后应切换到GoogleSignIn)。

        // Create the Google Api Client with access to Plus and Games
    mGoogleApiClient = new GoogleApiClient.Builder(this)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        //.addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
        .addApi(Games.API).addScope(Games.SCOPE_GAMES)
        .build();

欢迎任何提示或解决方法。

1 个答案:

答案 0 :(得分:1)

您的RoomStatusUpdate侦听器如何? RoomStatusUpdateCallback 您是否实现onPeerJoined(Room room,ListpartnerIds)方法?