- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试制作一款存储高分的游戏。
“在 Android 上实现登录”链接:
https://developers.google.com/games/services/training/signin#signing_the_player_in_at_startup
表示使用 MyGameProgress 类来保存分数、成就等。但是,当我尝试将变量声明为 MyGameProgress 时,出现“无法解析符号 MyGameProgress”(例如 MyGameProgress mGameProgress = new MyGameProgress() )
有人知道吗?
下面是我的 MainActivity.java 文件:
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.games.Games;
import com.google.example.games.basegameutils.BaseGameUtils;
public class MainActivity extends ActionBarActivity {
int Score = 0;
GoogleApiClient mGoogleApiClient;
MyGameProgress mGameProgress = new MyGameProgress();
private static int RC_SIGN_IN = 9001;
private boolean mResolvingConnectionFailure = false;
private boolean mAutoStartSignInFlow = true;
private boolean mSignInClicked = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
if (mResolvingConnectionFailure) {
// Already resolving
return;
}
// If the sign in button was clicked or if auto sign-in is enabled,
// launch the sign-in flow
if (mSignInClicked || mAutoStartSignInFlow) {
mAutoStartSignInFlow = false;
mSignInClicked = false;
mResolvingConnectionFailure = true;
// Attempt to resolve the connection failure using BaseGameUtils.
// The R.string.signin_other_error value should reference a generic
// error string in your strings.xml file, such as "There was
// an issue with sign in, please try again later."
if (!BaseGameUtils.resolveConnectionFailure(this,
mGoogleApiClient, connectionResult,
RC_SIGN_IN, "R.string.signin_other_error")) {
mResolvingConnectionFailure = false;
}
}
// Put code here to display the sign-in button
}
public void increaseScore(View view) {
Score = Score + 1;
TextView ScoreTextV = (TextView)findViewById(R.id.textView);
ScoreTextV.setText(Integer.toString(Score));
};
public void FinishGame(View view) {
//Games.Leaderboards.submitScore(getApiClient(),
// getString(R.string.leaderboard_high_score), Score);
// when user finishes level:
mGameProgress.addScore(userScore);
mGameProgress.addAchievement(fooAchievement);
mGameProgress.addAchievement(barAchievement);
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
mGameProgress.save(mGoogleApiClient);
}
}
}
在我的 build.gradle (module.app) 中,我将其包含在依赖项下:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':BaseGameUtils')
compile 'com.android.support:appcompat-v7:21.0.3'
//compile 'com.google.android.gms:play-services-games:6.5.87'
compile 'com.google.android.gms:play-services:6.5.+'
在我的 AndroidManifest.xml 中,我包括:
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
我还导入了 BaseGameUtils 模块。
为方便起见,这是我在上面提供的“在 Android 上实现登录”链接中的代码 fragment :
MyGameProgress mGameProgress = ....;
// when user finishes level:
mGameProgress.addScore(userScore);
mGameProgress.addAchievement(fooAchievement);
mGameProgress.addAchievement(barAchievement);
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
mGameProgress.save(mGoogleApiClient);
}
@Override
protected void onConnected() {
// sign in successful, so save progress if we have any.
if (mGameProgress != null) {
mGameProgress.save(mGoogleApiClient);
}
// ...
}
如果我需要自己创建 MyGameProgress 类,我不知道如何创建“保存”方法以便将高分保存到游戏服务云中。
我还看到了一些关于保存游戏进度的“快照”。你认为这是更好的方法吗?我应该改为研究这样做吗?
最佳答案
事实证明,MyGameProgress(它有一个“保存”方法)是文档要我创建的一个类。
但是,我可以改用 Games.Leaderboards.submitScore 方法。
我能够让它与声明一起工作:Games.Leaderboards.submitScore(mGoogleApiClient, getString(R.string.leaderboard_high_score), Score);
注意:本来有些文档说要用Games.Leaderboards.submitScore(getApiClient(), getString(R.string.leaderboard_high_score), Score);
但 getApiClient() 部分使其无法正常工作。在我将其替换为GoogleApiClient 变量 mGoogleApiClient。
关于android - 什么是 MyGameProgress 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29039638/
我正在尝试制作一款存储高分的游戏。 “在 Android 上实现登录”链接: https://developers.google.com/games/services/training/signin#
我是一名优秀的程序员,十分优秀!