-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGamePanel.java
More file actions
61 lines (50 loc) · 1.6 KB
/
GamePanel.java
File metadata and controls
61 lines (50 loc) · 1.6 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.example.jason.a4x4;
import android.content.Context;
import android.graphics.Canvas;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
/**
* Created by JASON on 8/30/2018.
*/
public class GamePanel extends SurfaceView implements SurfaceHolder.Callback {
private MainThread thread;
private SceneManager manager;
public GamePanel(Context context){
super(context);
getHolder().addCallback(this);
thread = new MainThread(getHolder(), this);
manager = new SceneManager(context);
setFocusable(true);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height){
}
@Override
public void surfaceCreated(SurfaceHolder holder){
thread = new MainThread(getHolder(), this);
if (thread != null) {
thread.setRunning(true);
thread.start();
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder){
if (thread != null) {
thread.setRunning(false);
}
}
@Override
public boolean onTouchEvent(MotionEvent event){
manager.receiveTouch(event);
return true;
}
public void update(){
manager.update();
}
@Override
public void draw(Canvas canvas){
super.draw(canvas);
manager.draw(canvas);
}
}