Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Google Play Game Services with LibGdx

I would like to use achievement and leaderboards from Google Play Game Services API in my LibGDX Android Game. The only thing I've achieved is getting examples from Game Services developer website running. I've been trying to use this code in my project for many days and I still got nothing. I've also tried to follow this tutorial http://helios.hud.ac.uk/u1070589/blog/?p=202 but I don't have "main game class (the one that extends from ApplicationListener)" which is required in step 7. I've got only

  • public class DogeJump extends Game
  • public class MainActivity extends AndroidApplication implements IActivityRequestHandler
  • public class BaseScreen implements Screen
  • public class GameScreen extends BaseScreen //which is responsible for the gameplay

This is onCreate method from MainActivity.java

    protected void onCreate(Bundle savedInstanceState) {

           super.onCreate(savedInstanceState);
        thingy=this;

        RelativeLayout layout=new RelativeLayout(this);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        View gameView=initializeForView(new DogeJump(this),false);

        adView=new AdView(this,AdSize.IAB_MRECT,"ca-app-pub-XXXXXXX363095/9011689567");

        adView.loadAd(new AdRequest());

        layout.addView(gameView);
        RelativeLayout.LayoutParams adParams=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
        adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
        adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        layout.addView(adView,adParams);       



        setContentView(layout);

        //initialize(new DogeJump(this),false);
    }
like image 770
Pawelnr1 Avatar asked Nov 01 '22 13:11

Pawelnr1


1 Answers

Off the top of my head, Game class should implement ApplicationListener, so the class you're missing to follow the tutorial should be DogeJump.

like image 62
ssantos Avatar answered Nov 15 '22 04:11

ssantos