【问题标题】:How to display Google Game Services popups in libGDX?如何在 libGDX 中显示 Google 游戏服务弹出窗口?
【发布时间】:2018-06-17 05:36:11
【问题描述】:

我一直在尝试在我的 LibGDX 项目中添加 setPopUpView(),但它没有显示。这是我的代码。

 private void signInSilently() {
        mGoogleSignInClient.silentSignIn().addOnCompleteListener(this,
                new OnCompleteListener<GoogleSignInAccount>() {
                    @Override
                    public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
                        if (task.isSuccessful()) {
                            GoogleSignInAccount signedInAccount = task.getResult();
                            GamesClient gamesClient = Games.getGamesClient(AndroidLauncher.this, signedInAccount);
                            View view = new View(AndroidLauncher.this);
                            gamesClient.setGravityForPopups(Gravity.TOP);
                            gamesClient.setViewForPopups(view);
                            onConnected(task.getResult());
                            Log.d(TAG, "signInSilently(): success");
                        } else {
                            onDisconnected();
                            Log.d(TAG, "signInSilently(): failure", task.getException());
                        }
                    }
                });
    }

【问题讨论】:

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


    【解决方案1】:

    您应该从AndroidLauncher 活动中检索View

    GamesClient gamesClient = Games.getGamesClient(AndroidLauncher.this, signedInAccount);
    gamesClient.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
    gamesClient.setViewForPopups(((AndroidGraphics) AndroidLauncher.this.getGraphics()).getView());
    // or, which is the same thing
    // gamesClient.setViewForPopups(((AndroidGraphics) Gdx.graphics).getView());
    

    您可能希望将这三行代码放在onConnected() 方法中。

    【讨论】:

      猜你喜欢
      • 2015-03-01
      • 2014-12-26
      • 2018-05-05
      • 2018-05-12
      • 1970-01-01
      • 2013-09-27
      • 1970-01-01
      • 2014-04-17
      • 1970-01-01
      相关资源
      最近更新 更多