【问题标题】:How to properly cancel a realtime multiplayer match?如何正确取消实时多人比赛?
【发布时间】:2014-07-09 03:09:10
【问题描述】:

如果用户在等候室阶段取消比赛,如何正确取消实时多人比赛?此时,没有“房间 id”可以调用leave API。

首先创建一个快速游戏:

Bundle am = RoomConfig.createAutoMatchCriteria(1, 1, 0);
RoomConfig.Builder roomConfigBuilder = configRoom();
roomConfigBuilder.setAutoMatchCriteria(am);
RoomConfig roomConfig = roomConfigBuilder.build();
Games.RealTimeMultiplayer.create(getApiClient(), roomConfig);

然后onRoomCreated被触发并显示一个等候室:

Intent i = Games.RealTimeMultiplayer.getWaitingRoomIntent(getApiClient(), room, Integer.MAX_VALUE);
startActivityForResult(i, RC_WAITING_ROOM);

之后用户按下回,取消匹配。然后onActivityResultRC_WAITING_ROOMresponseCode == Activity.RESULT_CANCELED 触发。

问题是比赛还在,等待另一个玩家。如果有人在 10 分钟后也开始快速游戏,游戏就会开始!

用户取消后如何清理?

【问题讨论】:

    标签: android google-play-games


    【解决方案1】:

    onActivityResult extra 有房间信息(即使已取消):

    Room room = intent.getExtras().getParcelable(Multiplayer.EXTRA_ROOM);
    

    那你只需要离开房间:

    Games.RealTimeMultiplayer.leave(getApiClient(), this, room.getRoomId());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-25
      • 2012-10-03
      • 2016-01-11
      • 1970-01-01
      • 1970-01-01
      • 2018-05-24
      • 2017-10-29
      相关资源
      最近更新 更多