i do my first game and already read alot about design strategie, programming style, design .. and so on theoretically it works perfect but in practice i dont know if i do thinks "right"
i have three classes my main which starts the view in this i do all my stuff -currently-
it holds an state variable, it has an onDraw method .. and so on
the third class is the game-thread while my game is running, in here are decisions -depending on my current state- what should be done
@Override
public void run() {
Canvas canvas = null;
mStartTime = System.currentTimeMillis();
while (mRun) {
canvas = mHolder.lockCanvas();
if (canvas != null) {
// State Updating State means to manage state transitions, such as a game over, character select or next level.
switch( mPanel.getModeState() ){
case Surface.MODE_LOGO_SPLASH :
break;
case Surface.MODE_MENU :
// the menu
break;
case Surface.MODE_LOADING :
// loading animation
break;
case Surface.MODE_GAME_PLAYING :
// game stuff
// GAME START _ RUNNING _ END
// Input
// AI
// Physics
// animation
//mPanel.animate(mElapsed);
break;
}
// draw everyThing
mPanel.doDraw(mElapsed, canvas);
// sound
// Sound and Video.
mElapsed = System.currentTimeMillis() - mStartTime;
mHolder.unlockCanvasAndPost(canvas);
}
mStartTime = System.currentTimeMillis();
}
}
my problem is .. the function onDraw draws everything .. including the menu ? this sounds for me like bad code because everytime doDraw is executet, i have to check in this function which state i am currently in .. this cost time, dosent it ?
public void doDraw(long elapsed, Canvas canvas) {
canvas.drawColor(Color.BLACK);
// currently just gameLayout
canvas.drawBitmap(background, 0, 0, mPaint);
gameLayout.draw(canvas);
}
would it not be better do implement an other thread which draws the menu ? but if so, how can i overlay the menu afer pause the game ?
:\ thanks for help erwin