【问题标题】:How to get the Profile image of Participant in RealTimeMultiplayer using Google Play Game Services如何使用 Google Play 游戏服务在 RealTimeMultiplayer 中获取参与者的个人资料图像
【发布时间】:2014-05-05 23:18:33
【问题描述】:

我正在使用基于 RealTimeMultiplayer 概念的 google play 游戏服务构建游戏,我的问题是如何访问所有参与者的个人资料图像以显示。我是 google play 游戏服务的新手,没有找到解决方案或任何关于 API 的指导。请指导我,我们可以访问以及如何访问?

【问题讨论】:

    标签: android google-plus multiplayer google-play-games


    【解决方案1】:

    使用 ImageManager 类加载 ImagerUri 是我的解决方法。

    下面,我遍历 currentRoom 中的每个 Participant,并请求 ImageManager 实例加载它们的 IconImageUri。

    这可以直接用于膨胀视图,但由于我使用的是 LibGDX,所以我将其保存为 png 以供其处理。

    (你可以看到我告诉 GameInterface 如果他们没有图片,则它为 null,或者因为没有图片,或者他们是“未知”参与者,因此 GPGS 返回 null)

            for (Participant p : mRoomCurrent.getParticipants()) {
    
                //makeToast("should be loading pic");
                ImageManager IM = ImageManager.create(this);
                IM.loadImage(new ImageManager.OnImageLoadedListener() {             
    
                    @Override
                    public void onImageLoaded(Uri arg0, Drawable drawable, boolean arg2) {
                        if(drawable == null) {
                            theGameInterface.picLoaded(participantID, null);
                        } else {
                            Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
                            try {
                               FileOutputStream out = openFileOutput("pic" + participantID + ".png", Context.MODE_MULTI_PROCESS);
                               bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
                               out.flush();
                               out.close();
                            } catch (Exception e) {
                                e.printStackTrace();
                                //dLog(e.getStackTrace().toString());
                            }
                        }
    
                }
                }, p.getIconImageUri());
    

    这些是从开发者网站推导出来的

    ImageManagerParticipant

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-02
      • 2016-06-17
      • 1970-01-01
      • 1970-01-01
      • 2016-08-31
      • 1970-01-01
      • 1970-01-01
      • 2013-06-16
      相关资源
      最近更新 更多