务获取RealTimeMultiplayer中参与者的个人资料图

务获取RealTimeMultiplayer中参与者的个人资料图

本文介绍了如何使用Google Play游戏服务获取RealTimeMultiplayer中参与者的个人资料图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用RealTimeMultiplayer概念上的Google Play游戏服务来构建游戏,我的问题是如何访问所有参与者的个人资料图像以进行显示.我是Google Play游戏服务的新手,未找到解决方案或有关API的任何指南.请指导我,我们可以访问以及如何访问吗?

I am building a game using google play game services on RealTimeMultiplayer concept, my questions is how to get access the all participants profile image to display. i am new to the google play game services, not found a solutions or any guidance on API. please guide me, can we access and how to access?

推荐答案

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

Using the ImageManager class to load the ImagerUri is how I tackle it.

下面,我遍历currentRoom中的每个参与者,并请求由ImageManager实例加载其IconImageUri.

Below, I loop through each Participant in the currentRoom, and request their IconImageUri to be loaded by an ImageManager instance.

这可以直接用于使视图膨胀,但是当我使用LibGDX时,我将其另存为png以供处理.

This can directly be used to inflate a view, but as I am using LibGDX, I save it as png for it to handle.

(您可以看到,如果他们没有照片,我会告诉GameInterface它为null,要么是因为没有图片,要么是他们是未知"参与者,因此GPGS返回null)

(You can see that I tell theGameInterface that it is null if their is no pic, either because there isn't one, or they are an "unknown" participant and therefore GPGS returns 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());

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

These were deduced from developer site

ImageManager 参与者

这篇关于如何使用Google Play游戏服务获取RealTimeMultiplayer中参与者的个人资料图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 22:14