来自 google 服务的实时多人游戏问题(向您的房间配置添加独占位掩码)

The issue with real-time multiplayer from google services (adding an exclusive bitmask to your room configuration)

所以,我正在写基于Google服务的实时多人游戏(Real-time Multiplayer)。我想为自动匹配标准添加不同的角色。在 google 文档中它看起来像这样:

If your game has multiple player roles (such as farmer, archer, and wizard) and you want to restrict auto-matched games to one player of each role, add an exclusive bitmask to your room configuration. When auto-matching with this option, players will only be considered for a match when the logical AND of their exclusive bit masks is equal to 0. The following example shows how to use the bit mask to perform auto matching with three exclusive roles:

在这个例子中,我们将等待 2 个具有专属角色的随机对手。

private static final long ROLE_FARMER = 0x1; // 001 in binary
private static final long ROLE_ARCHER = 0x2; // 010 in binary
private static final long ROLE_WIZARD = 0x4; // 100 in binary

    private void startQuickGame(long role) {
        // auto-match with two random auto-match opponents of different roles
        Bundle am = RoomConfig.createAutoMatchCriteria(2, 2, role);

        // build the room config
        RoomConfig.Builder roomConfigBuilder = makeBasicRoomConfigBuilder();
        roomConfigBuilder.setAutoMatchCriteria(am);

        // create room, etc.
        // ...
    }

当我将独占角色替换为 0 时,它工作正常。但如果我为每个对手添加一些位掩码,例如 0x1,它就不起作用。玩家不连接到房间。我用实时多人游戏的 google 示例测试了这个问题:https://github.com/playgameservices/android-basic-samples/tree/master/BasicSamples/ButtonClicker 它也不起作用。你能帮我解决这个问题吗?我解决不了。

所以,我解决了我的问题。如果您想将玩家与特定选项联系起来。你需要使用 roomConfigBuilder.setVariant(0x4);