【问题标题】:Intent is not working to get highscore意图无法获得高分
【发布时间】:2013-07-20 09:43:25
【问题描述】:

cocos2d 游戏开发终于结束了,为了得到这个,我将 totalScore 发送到下一个 gameover.class 活动以设置为高分,如果它是高的并且想要显示分数和玩家姓名。我已经这样做了,但是一旦游戏结束,我就无法进行 gameover.class 活动,不知道我哪里出错了。请帮帮我

这是我的游戏层(第一个活动)

 if (spriteCounter<=0)
                {


                    Intent mainScore = new Intent(CCDirector.sharedDirector().getActivity(), GameOver.class);
                    mainScore.putExtra("totalscore", countScore);
                    CCDirector.sharedDirector().getActivity().startActivity(mainScore);
                    System.out.println("------------");
                    CCDirector.sharedDirector().getActivity().finish();

                 }

gameover.class(第二个活动)

public class GameOver extends MainActivity {

ImageView playagain, home;
String[] columns;
int Score = 0;
String TOTALSCORE = "score";
String PLAYERNAME = "playername";

SQLiteDatabase db;

SharedPreferences sharedPreference = CCDirector.sharedDirector()
        .getActivity().getSharedPreferences("sharedPreference", 0);

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.gameover);

    int totalscore = getIntent().getIntExtra("totalscore", -1);
    SharedPreferences sharedPreference = CCDirector.sharedDirector()
            .getActivity().getSharedPreferences("sharedPreference", 0);
    long temp_totalscore = (long) totalscore;
    try {
        String bp_totalscore = sharedPreference.getString(TOTALSCORE, null);
        String bp_playername = sharedPreference.getString(PLAYERNAME, null);
        if (totalscore > Integer.parseInt(bp_totalscore)) {

            showSettingsDialog(temp_totalscore);

        }

    } catch (Exception e) {
        showSettingsDialog(temp_totalscore);
    }

    intiatizeviews();
    viewlisteners();

}

private void showSettingsDialog(long totalscore) {
    EnterHighscore dialog = new EnterHighscore(this, totalscore);

    dialog.show();

}

private void intiatizeviews() {
    playagain = (ImageView) findViewById(R.id.playagainimageView);
    home = (ImageView) findViewById(R.id.homeimageView);

}

【问题讨论】:

  • I'm not able to get gameover.class activity - 这是什么意思? 究竟会发生什么?
  • 这个活动显示总分和玩家@Simon的名字
  • 你遇到了什么错误?

标签: android android-intent android-activity cocos2d-iphone cocos2d-android


【解决方案1】:

但是一旦游戏结束我就无法获得gameover.class 活动

假设您的问题是在启动此新活动时应用程序崩溃,logcat 显示找不到gameover 类,您是否在清单文件中注册了此GameOver Activity

【讨论】:

    猜你喜欢
    • 2023-03-05
    • 1970-01-01
    • 2018-10-09
    • 1970-01-01
    • 1970-01-01
    • 2017-12-21
    • 2018-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多