Back to project page jmjuanesFramework.
The source code is released under:
MIT License
If you think the Android project jmjuanesFramework listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package jmjuanes.core; //ww w . jav a2 s. c o m import jmjuanes.GameMain; import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.view.MotionEvent; import android.view.SurfaceHolder; import android.view.SurfaceView; @SuppressWarnings("unused") public class GameView extends SurfaceView implements SurfaceHolder.Callback { //Context private final Context context; //Thread principal public GameThread thread; //Tiempo del thread public int thread_time = 0; //Activity principal public GameMain game; //Clase del load public GameLoad load; //Para saber si estamos en el loadind public boolean loading = false; public GameView(Context context, GameMain game) { //Guardamos el context super(context); this.context = context; //Guardamos el activity this.game = game; //Iniciamos el bucle getHolder().addCallback(this); } @Override public void surfaceCreated(SurfaceHolder holder) { //Comprobamos si el screen ha sido inicializado if(game.screen_actual == "") { //Iniciamos el loader load = new GameLoad(this, game); } else { //Si ya lo hemos cargado todo game.ResumeView(); } } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {} @Override public void surfaceDestroyed(SurfaceHolder holder) { //Para saber si se ha detenido boolean retry = true; //Marcamos para que pare ThreadStop(); //Mientras no se haya detenido while(retry) { try { thread.join(); retry = false; } catch(InterruptedException e) { } } } //Funcion que crea un nuevo bucle public void ThreadCreate() { //Iniciamos el Thread thread = new GameThread(getHolder(), this); thread.setRunning(true); thread.start(); } //Funcion que inicia el bucle public void ThreadStart() { //Comprobamos si el bucle no esta ya iniciado if(thread.getRunning() == false) { //Creamos un nuevo bucle ThreadCreate(); } } //Funcion que detiene el bucle public void ThreadStop() { //Marcamos para que detenga el buble thread.setRunning(false); } //Funcion draw canvas public void OnDraw(Canvas canvas) { //Comprobamos si estamos en el loading if(loading == true) { //Aumentamos el contador de frames GameFrames.contador ++; } if(canvas != null) { //Ponemos el fondo canvas.drawColor(Color.WHITE); //Mandamos el draw al activity game.Draw(canvas); } } }