-3

I'm trying to use the measured height and add it too my if statement so that when 'blueY' touches the bottom of the screen it results in game over. Not sure if error is in getting the height or if it is with the if statement.

My if statement is as follows:

    if (blueY >= height) {
        // Game Over
        timer.cancel();
        timer = null;

        Intent intent = new Intent(getApplicationContext(), Results.class);
        intent.putExtra("SCORE", score);
        startActivity(intent);

    }

and in onCreate:

    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    height = mFrame.getMeasuredHeight() -  startLabel.getMeasuredHeight() ;
    // I have also tried this :height  = displayMetrics.heightPixels;
    width = displayMetrics.widthPixels;

I am very new to Java so sorry if this sound dumb.

liam
  • 9
  • 2
  • 3
  • Possible duplicate of [Get screen dimensions in pixels](https://stackoverflow.com/questions/1016896/get-screen-dimensions-in-pixels) – Firerazzer May 22 '17 at 14:06
  • "I assume I need to get the height of the screen in order for this to work" -- no, you need to get the height of your game play area (e.g., whatever `View` you are using for rendering the game). That is not the height of the screen in many cases. – CommonsWare May 22 '17 at 14:41

2 Answers2

0

This is duplicated questions!

    Display display = ((WindowManager) this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int mWidthScreen = display.getWidth();
    int mHeightScreen = display.getHeight();
redAllocator
  • 725
  • 6
  • 12
0

I found the solution to making the game end (timer stop) when the image touches the bottom of the screen:

  if (blueY >= frameHeight-blueSize) {
        // Game Over
        timer.cancel();
        timer = null;

}

liam
  • 9
  • 2
  • 3