Android Game Leader Board: Where to extends BaseGameActivity?

无人久伴 提交于 2019-12-13 05:57:46

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/30850929/android-game-leader-board-where-to-extends-basegameactivity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!