0

i have set some condition in the cocos2d-android game app, if the condition=0, the current gamelayers score will be displayed in Gameover.class as highscore, but here when the condition becomes zero, i'm not able to get next layer(Gameover.class) which displays highscore and an option to save the player name.

if (Counter<=0)
                {

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

i have used the above code, the print statement is not getting, i guess this line CCDirector.sharedDirector().getActivity() .startActivity(mainScore); has problem, please can anybody solve this issue?

This is the Gameover.class

public class GameOver extends BaseActivity {

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();

}
DD.
  • 973
  • 2
  • 10
  • 32

1 Answers1

0

is you gameover.class an activity. i think not. as its not an activity but a scene in cocos2d. replace your code with this.

CCScene scene=GameOver.scene(); 
    CCDirector.sharedDirector().replaceScene(scene);
Sandeep R
  • 2,284
  • 3
  • 25
  • 51
  • gameover.class is an activity, i had given connection between Scene and Activity – DD. Aug 03 '13 at 05:06
  • there will be only one activity to start the game scene and then from there the scenes change from one scene to another that is what you want, is it? from game scene to gameover scene you need the above provided code. try that code in your game once. and.. you should not extend activity but CClayer. – Sandeep R Aug 03 '13 at 05:08
  • I got your point.but you should not extend an activity and make it an activity. in android cocos2d game there will be layers and scenes. so extend CCLayer instead of baseactivity. – Sandeep R Aug 03 '13 at 05:12
  • but i dont want CCLayer, i had done some animation in activity so need to use activity only, found this is easy instead of doing in CCScene – DD. Aug 03 '13 at 05:54