我正在努力在游戏中实现Play Game Services,但尝试将分数从gamePanel提交到排行榜时一直遇到问题。我无法在我的GameActivity之外的任何地方运行该方法,如果我尝试在其他地方调用它会扩展BaseGameActivity,但我收到上面的错误。
提交分数的方法
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);
}
}
需要调用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();
}
}
最佳答案
您可以尝试以下方法:
static void updatePlayThingies(GoogleApiClient apiClient){
int distance= MainGamePanel.Squirrel.getDist();
if(gameover==true){
Games.Leaderboards.submitScore(apiClient, "CgkIkfSPtJocEAIQAQ", distance);
}
并像tis一样调用updatePlayThingies:
updatePlayThinges(getApiClient());