Rev 193 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package com.gebauz.Bauzoid.app;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
/** Base Activity class for Bauzoid applications.
* Derive from this Activity class to implement own Bauzoid applications.
*/
public abstract class GameActivity
extends Activity
{
protected GLSurfaceView mGameView =
null;
protected Game mGame =
null;
/** Called when the activity is first created. */
public void onCreate
(Bundle savedInstanceState,
int layoutId,
int glSurfaceId
)
{
Log.
v(Consts.
LOG_TAG,
"GameActivity.onCreate()");
super.
onCreate(savedInstanceState
);
getWindow
().
setFormat(PixelFormat.
TRANSLUCENT);
getWindow
().
setWindowAnimations(0);
requestWindowFeature
(Window.
FEATURE_NO_TITLE);
getWindow
().
setFlags(WindowManager.
LayoutParams.
FLAG_FULLSCREEN, WindowManager.
LayoutParams.
FLAG_FULLSCREEN);
setContentView
(layoutId
);
mGameView =
(GLSurfaceView
)findViewById
(glSurfaceId
);
mGameView.
setEGLContextClientVersion(2);
mGameView.
setEGLConfigChooser(8,
8,
8,
8,
16,
0);
mGameView.
setRenderer(new GameRenderer
(this));
//mGameView.setOnTouchListener(this);
// set landscape mode
setRequestedOrientation
(ActivityInfo.
SCREEN_ORIENTATION_LANDSCAPE);
}
@
Override
protected void onDestroy
()
{
Log.
v(Consts.
LOG_TAG,
"GameActivity.onDestroy()");
super.
onDestroy();
if (mGame
!=
null)
{
exit
();
mGame.
exit();
mGame =
null;
}
}
@
Override
protected void onResume
()
{
Log.
v(Consts.
LOG_TAG,
"GameActivity.onResume()");
super.
onResume();
mGameView.
onResume();
}
@
Override
protected void onPause
()
{
Log.
v(Consts.
LOG_TAG,
"GameActivity.onPause()");
super.
onPause();
mGameView.
onPause();
}
@
Override
protected void onStart
()
{
Log.
v(Consts.
LOG_TAG,
"GameActivity.onStart()");
super.
onStart();
}
@
Override
protected void onStop
()
{
Log.
v(Consts.
LOG_TAG,
"GameActivity.onStop()");
super.
onStop();
}
@
Override
public void onWindowFocusChanged
(boolean hasFocus
)
{
Log.
v(Consts.
LOG_TAG,
"GameActivity.onWindowFocusChanged(" + hasFocus +
")");
super.
onWindowFocusChanged(hasFocus
);
}
/** Called when the surface is lost and about to be recreated. */
public void onSurfaceLost
()
{
Log.
v(Consts.
LOG_TAG,
"GameActivity.onSurfaceLost()");
if (mGame
!=
null)
{
mGame.
onSurfaceLost();
}
}
/** Called when the surface is created. */
public void onSurfaceCreated
()
{
Log.
v(Consts.
LOG_TAG,
"GameActivity.onSurfaceCreated()");
if (mGame ==
null)
{
// create Game instance - loads resources at this point
mGame =
new Game
(this);
mGame.
init();
init
();
}
else
{
// recreate resources
mGame.
onSurfaceRecreated();
}
}
/** Called when the surface is changed. */
public void onSurfaceChanged
(int w,
int h
)
{
Log.
v(Consts.
LOG_TAG,
"GameActivity.onSurfaceChanged()");
mGame.
onSurfaceChanged(w, h
);
}
/** Called for game logic updates inside the game logic thread. */
public void update
(float deltaTime
)
{
mGame.
update(deltaTime
);
}
/** Called for rendering inside the GL render thread. */
public void render
()
{
mGame.
render();
}
/** Called for initialization after GL context and engine internals have been initialized. */
public abstract void init
();
/** Called before destruction of the engine internals and GL context. */
public abstract void exit
();
}