0

I'm trying to make a simple android game. I have a surfaceview named: surfaceviewgame, which is responsible for the drawing, updating and handling touch events of the game. At this point I'm checking if the gamestate is "game-over" in this surfaceview by setting the "pause" boolean to true. Now, I want to read this pause variable like this:

SurfaceViewGame v;

if(v.pause == true){
    setcontentview(R.Layout.pause)
}

But I can't simply paste that if statement in the activity below. Does someone know how to approach this problem?

public class StartGame extends Activity {

SurfaceViewGame v;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    v = new SurfaceViewGame(this);
    setContentView(v);
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    v.pause();
}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    v.resume();
}

}

Fred
  • 3
  • 1

1 Answers1

0

You can pass some callback object from your activity to your SurfaceView, or make your activity such a callback and notify it about any changes in game flow. Then in your callback method you can resolve next behaviour.

Orest Savchak
  • 4,529
  • 1
  • 18
  • 27
  • Can you be more specific about the kind of callback method you mean? Maybe give an example snippet of how you would approach it? – Fred May 25 '15 at 18:02
  • Thanks! Finally got it. If someone has the same problem, this link was very helpful for me to understand callbacks: http://stackoverflow.com/questions/18054720/what-is-callback-in-android – Fred May 28 '15 at 15:36
  • Sorry, was not able. I'm not sure I have answered your question, but I hope it'll show you right way. – Orest Savchak May 28 '15 at 17:38