-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainActivity
48 lines (33 loc) · 1.28 KB
/
MainActivity
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package android.example.spaceinvproject;
import android.app.Activity;
import android.graphics.Point;
import android.os.Bundle;
import android.view.Display;
import android.view.MotionEvent;
public class MainActivity extends Activity {
SpaceGameView spaceGameView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Display display = getWindowManager().getDefaultDisplay(); //allows us to know size of device screen
//passes back lower right XY co-ords (top left XY co-ords = 0,0)
Point size = new Point();
display.getSize(size); //retrieves screen size
spaceGameView = new SpaceGameView(this, size.x, size.y);
setContentView(spaceGameView);
}
// This method executes when the player starts the game
@Override
protected void onResume() { //Calls resume method to restart game thread
super.onResume();
// Tell the gameView resume method to execute
spaceGameView.resume();
}
// This method executes when the player quits the game
@Override
protected void onPause() { //stops game thread by calling onPause method
super.onPause();
// Tell the gameView pause method to execute
spaceGameView.pause();
}
}