gpt4 book ai didi

android - Google Play 实时多人游戏问题

转载 作者:太空狗 更新时间:2023-10-29 16:18:22 26 4
gpt4 key购买 nike

我有一些问题在文档中没有得到解答:https://developers.google.com/games/services/android/multiplayer

  1. RoomConfig.createAutoMatchCriteria(1, 3, 0) 未按预期工作。它只会尝试匹配 2 人游戏,永远不会是 3 人游戏,也不会是 4 人游戏。我只有 3 台设备,但我可能花了 2 个小时来尝试匹配这些设备,而且它们只是成对完成的。我读了这篇文章:Auto Match Criteria in Google Multiplayer Sample BittonClicker Game for android有类似的问题。 GamesClient.getSelectPlayersIntent(1, 3) 也有同样的错误。

  2. GamesClient.getRealTimeWaitingRoomIntent(room, 0) 未按预期工作。文档指出“如果连接的参与者数量大于或等于指定的最小开始游戏,则启用等候室 UI 中的开始播放选项。”但是在测试时我还没有看到“开始播放”选项。发生的情况是,在弹出“准备玩”的消息后,每当第一个人连接时,等候室就会自动退出。从 0 更改为 1 具有相同的效果,更改为 Integer.MAX_VALUE 也是如此。谁能提供一种方法来实现预期的功能?我在这里做错了吗?

  3. 我在 Android 上玩过一些多人游戏,用户加入,然后离开,然后由其他人取代他们的位置。无论我为自动匹配假设什么参数,我都无法在测试中看到这一点。如果一个玩家离开房间,另一个玩家会来填补他的位置吗?如果是这样,`Room.getParticipantIds().size() 会返回一个大于 4 的数字吗?

  4. 在其中一些游戏中,一旦游戏开始就没有其他人加入。我测试了这些游戏,没有一次发现我加入了一个房间并被告知它正在进行中。他们是否以某种方式告诉服务器游戏已经开始,而不是让他们与其他玩家匹配?其他玩家如何只加入尚未开始的游戏? (这些游戏使用的是 Google Play 游戏服务)

我还有其他问题,但我不想问不必要的问题。这些问题会很有帮助,如果得到回答,我的压力会大大减轻。

感谢您的宝贵时间。

最佳答案

1) 这完全符合 Google 的预期。不保证如果您使用 createAutoMatchCriteria(1, 3, 0) 将为您的游戏找到 3 个对手。在我的测试中,(同时请求 4 个设备)90% 或更多的时间它将变成 2 个开始的 2 个游戏。仅当我有一台设备邀请 friend 或手动选择自动选择时,开始 3 人或 4 人游戏的机会才会显着增加(否则,纯自动匹配会导致 2 和 2 行为)

2) 如果我对行为的理解正确,你会得到一个玩家离开等候室(通常是第一个启动的设备)然后另一个玩家加入,但第一个玩家离开等候室,另一个离开在里面?如果是这样,那么您需要确保使用以下内容(我在 onRoomConnected 中执行

try {
bWaitRoomDismissedFromCode = true;
finishActivity(RC_WAITING_ROOM);
} catch (Exception e) {
dLog("would have errored out in waiting room");
}

这将关闭仍在等候室中的所有玩家的等候室,并让他们回到您的 Activity 中。从下面看,如果你想要“开始玩”的行为,这只有在有接受邀请的受邀玩家进入房间时才会发生。 (如果 Google 打算以另一种方式为 AutoMatch 工作,他们还没有做到这一点)

public Intent getRealTimeWaitingRoomIntent (Room room, int minParticipantsToStart)

Returns an intent that will display a "waiting room" screen that shows the progress of participants joining a real-time multiplayer room. Note that this must be invoked with startActivityForResult(Intent, int), so that the identity of the calling package can be established.

If the necessary number of peers have connected and it's now OK to start the game, or if the user explicitly asked to start the game now, the activity result will be RESULT_OK. If the user bailed out of the waiting room screen without taking any action, the result will be RESULT_CANCELED. If the user explicitly chose to leave the room, the result will be RESULT_LEFT_ROOM.

Regardless of what the result code was, the waiting room activity will return a data intent containing a Room object in EXTRA_ROOM that represents the current state of the Room that you originally passed as a parameter here.

If desired, the waiting room can allow the user to start playing the game even before the room is fully connected. This is controlled by the minParticipantsToStart parameter: if at least that many participants (including the current player) are connected to the room, a "Start playing" menu item will become enabled in the waiting room UI. Setting minParticipantsToStart to 0 means that "Start playing" will always be available, and a value of MAX_VALUE will disable the item completely. Note: if you do allow the user to start early, you'll need to handle that situation by explicitly telling the other connected peers that the game is now starting; see the developer documentation for more details.

Finally, note that the waiting room itself will never explicitly take any action to change the state of the room or its participants. So if the activity result is RESULT_LEFT_ROOM, it's the caller's responsibility to actually leave the room. Or if the result is RESULT_CANCELED, it's the responsibility of the caller to double-check the current state of the Room and decide whether to start the game, keep waiting, or do something else. But note that while the waiting room is active, the state of the Room will change as participants accept or decline invitations, and the number of participants may even change as auto-match players get added.

3) Google Play 游戏服务(用于自动匹配)没有此行为。只有当一个房间的所有参与者都被服务器找到并选中时,房间才会真正连接起来(onRoomCreated 并不意味着已经设置了一个用于通信的房间,如果玩家正在等待其他人加入,则玩家可以加入...并且可以在服务拥有所有其他玩家后进行切换)onRoomConnected 是对所有已连接玩家的最后一次调用,表示房间已准备好传递消息。现在,如果你有邀请,行为会改变,是的,你可以看到被邀请者接受,但如果他们随后离开房间.. 没有办法让 AutoMatch 填充它,但你可以看到他们离开。 ..(多好啊?)

4) 如果游戏使用 GPGS,那么一旦房间被创建并进入 onRoomConnected 阶段,它就会被玩,并且不能与该房间进行更多的比赛。所以当你加入一个房间时,其他人也会同时加入。因此,当一名玩家离开时,其他人将无法加入。

public abstract void onRoomConnected (int statusCode, Room room)

Called when all the participants in a real-time room are fully connected. This gets called once all invitations are accepted and any necessary automatching has been completed. Possible status codes include:

STATUS_OK if data was successfully loaded and is up-to-date. STATUS_CLIENT_RECONNECT_REQUIRED if the client needs to reconnect to the service to access this data. STATUS_INTERNAL_ERROR if an unexpected error occurred in the service. Parameters room The fully connected room object. The room can be null if it could not be loaded successfully.

关于android - Google Play 实时多人游戏问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21688407/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com