【问题标题】:Waiting room in Play Games Multiplayer does not show connected playersPlay Games Multiplayer 中的等候室不显示已连接的玩家
【发布时间】:2019-06-19 19:16:27
【问题描述】:

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

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

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

假设已经有 4 人连接到候诊室,那么他们就不会见面了。所以他们不知道其他人已经连接了。只有当所有 7 名参与者都连接时,才会显示玩家的姓名。这种行为不会促使人们在所有玩家都连接之前留在候诊室,因为对他们来说,这就像他们独自等待一样。

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

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

Gradle 依赖项:

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();

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

【问题讨论】:

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


    【解决方案1】:

    您的 RoomStatusUpdate 监听器怎么样? RoomStatusUpdateCallback 你实现了 onPeerJoined(Room room, List参与者Ids) 方法吗?

    【讨论】:

    • 是的,我有这个方法。它将调用 updateRoom() 并且 updateRoom 内的唯一代码行是:mParticipants = room.getParticipants();。有没有可能我可以修改这个方法里面的等候室,让它更新屏幕?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-12
    • 2019-02-01
    • 1970-01-01
    • 2015-01-02
    • 2016-04-07
    • 1970-01-01
    • 2019-06-15
    相关资源
    最近更新 更多