user3467727
user3467727

Reputation: 1

Cannot make a static reference to the non-static method getApiClient() from the type BaseGameActivity

I'm working on implementing Play Game Services in a game and I keep running into a problem when trying to submit the score from the gamePanel to the leaderboard. I cannot run the method anywhere except my GameActivity which extends BaseGameActivity if i try to call it somewhere else i get the error above.

method to submit score

public class GameActivity extends BaseGameActivity implements View.OnClickListener{
static void updatePlayThingies(){
    int distance= MainGamePanel.Squirrel.getDist();
    if(gameover==true){
        Games.Leaderboards.submitScore(getApiClient(), "Leaderboard_id", distance);
    }

}

game logic that needs to call updatePlayThingies

public class Squirrel{
private int distance = 0;
public void phys(){
 if (speedx==0){
bouncecheck=0;
//ball stopped
//reset stats and move ball back to launcher
GameActivity.gameover=true;
GameActivity.paused=true;
    GameActivity.updatePlayThingies();
}
}

Upvotes: 0

Views: 237

Answers (2)

user3293488
user3293488

Reputation: 11

You can try this:

static void updatePlayThingies(){
int distance= MainGamePanel.Squirrel.getDist();
if(gameover==true){
    Games.Leaderboards.submitScore(
      newGoogleApiClient().getApiClient(), 
      "CgkIkfSPtJocEAIQAQ", distance);
}

Upvotes: 0

Ondřej Z
Ondřej Z

Reputation: 5174

You could try this:

static void updatePlayThingies(GoogleApiClient apiClient){
    int distance= MainGamePanel.Squirrel.getDist();
    if(gameover==true){
        Games.Leaderboards.submitScore(apiClient, "CgkIkfSPtJocEAIQAQ", distance);
    }

And call updatePlayThingies like tis:

updatePlayThinges(getApiClient());

Upvotes: 1

Related Questions