Android Game Leader Board:何处扩展BaseGameActivity? [英] Android Game Leader Board: Where to extends BaseGameActivity?

查看:165
本文介绍了Android Game Leader Board:何处扩展BaseGameActivity?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 activity_main_layout 有2个按钮:

  //点击
开始游戏< Button android:id =@ + id / btnStart/>

//如果没有登录Google Game play Service
//登录后点击

点击 btnStart 开始玩游戏:

  btnStart.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
//在点击
Intent intent = new Intent(MainActivity.this,game_play.class);
startActivity(intent);
finish();
}
});

如您所见,class game_play 玩和更新身高分数



我想知道在哪里扩展BaseGameActivity? 内部类MainActivity或game_play 两者



我尝试了很多次,但并不成功。

我真的是一个业余爱好者,我希望你给我一些想法。

解决方案

您是否浏览了快速入门指南?如果您是开发Android游戏的新手,这是一个很好的开始。要回答您的问题,您需要从要处理登录和调用游戏服务API的活动访问Play游戏服务。根据你的描述,这听起来像你的活动需要打电话(主要活动显示排行榜,而游戏活动很可能发布分数)。 / p>

从BaseGameActivity扩展活动确实不再需要(对于娱乐解释手表: BasegameActivity的死亡。你需要做的是实现处理初始化GoogleAPIClient的两个接口:

public class MainActivity extends Activity implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
}



要实施这些,请参阅示例和文档: https ://developers.google.com/games/services/android/init



你可以做在你的游戏活动中也是如此。应用程序将维护活动之间的登录状态,因此玩家不必登录两次。


My activity_main_layout has 2 buttons:

//Start game on click
<Button android:id="@+id/btnStart"/>

//If not sign in Google Game play Service
//Sign in then show leader board on click

<Button android:id="@+id/btnLeader board" />

Click on btnStart to begin playing game:

btnStart.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Perform action on click
            Intent intent = new Intent(MainActivity.this, game_play.class);
            startActivity(intent);
            finish();
        }
    });

As you can see, class game_play is the place to play and update height score.

I'm wondering where to extends BaseGameActivity? Inside class MainActivity or game_play or both of them?

I try many times but it's not successfull.

I'm really an amateur, I expect that you give me some ideas.

解决方案

Have you gone through the QuickStart Guide? This is a good place to start if you are new to developing games for Android. To answer you question, you need to access the Play Game Services from the activity that is going to handle signing in and calling game services APIs.

From your description it sounds like both your activities will need to make calls (the main activity is showing the leaderboard, and the game activity is most likely posting scores).

Extending your activity from BaseGameActivity really is not needed any longer (for an entertaining explanation watch: Death of BasegameActivity. What you do need to do is implement the two interfaces that handle initializing the GoogleAPIClient:

public class MainActivity extends Activity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { }

To implement these, refer to the samples and the doc: https://developers.google.com/games/services/android/init

You can do the same in your game activity. The application will maintain the login state between activities, so the player will not have to login twice.

这篇关于Android Game Leader Board:何处扩展BaseGameActivity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆