MySurfaceView
package com.example.shinelon.helloworld;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;;
import android.graphics.RectF;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import java.util.Vector;
public class MySurfaceView extends SurfaceView implements SurfaceHolder.Callback, Runnable {
private SurfaceHolder surfaceHolder;
private Canvas canvas;
private Boolean a = true;
public static int height;
public static int width;
private MyPlan plan;
private Vector<Bullet> bulletVector = new Vector<>();
private Vector<Boom> boomVector = new Vector<>();
private int count;
private GameSoundPool gameSoundPool;
public static int GAME_STATE = 0;
public MySurfaceView(Context context) {
super(context);
gameSoundPool = new GameSoundPool(context);
init();
}
private void init() {
surfaceHolder = getHolder();
surfaceHolder.addCallback(this);
setFocusable(true);
setKeepScreenOn(true);
setFocusableInTouchMode(true);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
new Thread(this).start();
height = getHeight();
width = getWidth();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
a = false;
}
@Override
public void run() {
Paint paint = new Paint();
BackGround backGround = new BackGround(BitmapFactory.decodeResource(getResources(), R.mipmap.bk));
plan = new MyPlan(BitmapFactory.decodeResource(getResources(), R.mipmap.myplane), BitmapFactory.decodeResource(getResources(), R.mipmap.hp));
BossPlan bossPlan = new BossPlan(BitmapFactory.decodeResource(getResources(), R.mipmap.bossplane));