Android Open Source - jmjuanesFramework Game Thread






From Project

Back to project page jmjuanesFramework.

License

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.

Java Source Code

package jmjuanes.core;
// w  w w.  j  ava 2  s.c  o m
import android.annotation.SuppressLint;
import android.graphics.Canvas;
import android.view.SurfaceHolder;

public class GameThread extends Thread
{
  //Surface Holder
  public SurfaceHolder sh;
  
  //Game View
  public GameView view;
  
  //Boolean para saber si esta funcionando
  public boolean run;
  
  //Constructor
  public GameThread(SurfaceHolder sh, GameView view)
  {
    //Guardamos el Surface Holder
    this.sh = sh;
    
    //Guardamos el Game View
    this.view = view;
  }
  
  //Para establecer si esta funcionando o no
  public void setRunning(boolean run)
  {
    //Establecemos
    this.run = run;
  }
  
  //Devuelve si esta funcionando o no
  public boolean getRunning()
  {
    //Devolvemos el run
    return this.run;
  }
  
  @SuppressLint("WrongCall")
  public void run()
  {
    //Iniciamos la variable canvas
    Canvas canvas;
    
    //Mientras este activado
    while(run)
    {
      //Iniciamos el canvas a null
      canvas = null;
      
      //Probamos
      try
      {
        //Creamos el canvas
        canvas = sh.lockCanvas(null);
        
        //Llamamos a la funcion del view que dibuja en el canvas
        synchronized(sh) { view.OnDraw(canvas); }
        
        //Para relentizar el thread
        try 
        {
          //Detenemos el tiempo establecido
          sleep(view.thread_time);
        }
        catch (InterruptedException e) { e.printStackTrace(); }
      }
      finally
      {
        if(canvas != null) sh.unlockCanvasAndPost(canvas);
      }
    }
  }
}




Java Source Code List

jmjuanes.Config.java
jmjuanes.GameMain.java
jmjuanes.Screen.java
jmjuanes.core.GameData.java
jmjuanes.core.GameFrames.java
jmjuanes.core.GameLoad.java
jmjuanes.core.GameThread.java
jmjuanes.core.GameTouch.java
jmjuanes.core.GameView.java
jmjuanes.util.Mathm.java
jmjuanes.util.Ui.java