【问题标题】:How do I use this new listener我如何使用这个新的监听器
【发布时间】:2014-02-14 13:19:35
【问题描述】:

我正在开发一个回合制多人安卓应用。

最初,我必须实现TurnBasedMultiplayerListener 并覆盖onTurnBasedMatchInitiated,但现在该接口已弃用,我需要使用this listener

问题是,我不知道如何使用它。我已经让我的类实现了接口,并重写了方法。

然后我创建一个turnBasedGame如下...

PendingResult<InitiateMatchResult> f =
    Games.TurnBasedMultiplayer.createMatch(gApiClient, tbmc);

现在我想我不得不说f.setResultCallback(...)但我不知道在里面放什么。

有什么建议吗?

【问题讨论】:

    标签: java android google-play-services


    【解决方案1】:

    您需要提供一个实现 ResultCallback 作为参数的类。

    public void MatchInitiatedCallback implements ResultCallback {
    
        @Override
        public void onResult(TurnBasedMultiplayer.InitiateMatchResult result) {
            // Check if the status code is not success;
            if (result.getStatus != GamesStatusCodes.STATUS_OK) {
                showError(statusCode);
                return;
            }
    
            TurnBasedMatch match = result.getMatch();
    
            // If this player is not the first player in this match, continue.
            if (match.getData() != null) {
                showTurnUI(match);
                return;
            }
    
            // Otherwise, this is the first player. Initialize the game state.
            initGame(match);
    
            // Let the player take the first turn
            showTurnUI(match);
        }
    }
    

    参考:https://developers.google.com/games/services/android/turnbasedMultiplayer#selecting_players_with_the_default_user_interface

    【讨论】:

    • 我以前试过。它说 void 是 MatchInitiatedCallback 的无效类型
    猜你喜欢
    • 2016-05-08
    • 1970-01-01
    • 1970-01-01
    • 2021-02-16
    • 1970-01-01
    • 2013-11-29
    • 1970-01-01
    • 2015-07-05
    • 1970-01-01
    相关资源
    最近更新 更多