android - Java How to move between SurfaceViews -


i'm developing game right , i'm having problem on how move between main menu , gameplay itself. when game starts, set mainmenupanel first view. then, i'll use canvas.draw button in mainmenu, when pressed go gamepanel.

is there way can use setcontentview again in mainmenupanel class? or there other way so? thanks!

p.s. i've thought using viewgroup, after read documentations still don't idea how use it.

mainactivity :

public class mainactivity extends activity {      @override     protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     gamepanel gp = new gamepanel(this);     mainpanel mp = new mainpanel(this);     //viewgroup vg = (viewgroup)(gp.getparent());      //remove title     requestwindowfeature(window.feature_no_title);      //set fullscreen     getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen);      setcontentview(mp);      } } 

mainmenupanel :

public class mainmenupanel extends surfaceview implements surfaceholder.callback{ public mainmenupanel(context context){     super(context);      //add callback surfaceview intercept events     getholder().addcallback(this);      setfocusable(true); } @override public void surfacechanged(surfaceholder holder, int format,int width, int height){}  @override public void surfacedestroyed(surfaceholder holder){ }  @override public void surfacecreated(surfaceholder holder){ } @override public boolean ontouchevent(motionevent event){     if(event.getaction() == motionevent.action_down ){         //code move gamepanel         }         return true;     }     if(event.getaction() == motionevent.action_up){         return true;     }     return super.ontouchevent(event); } } } 

gamepanel:

public class gamepanel extends surfaceview implements surfaceholder.callback{ private mainthread thread; public gamepanel(context context){     super(context);      //add callback surfaceview intercept events     getholder().addcallback(this);      //make gamepanel focusable can handle events     setfocusable(true); } @override public void surfacechanged(surfaceholder holder, int format,int width, int height){}  @override public void surfacedestroyed(surfaceholder holder){ }  @override public void surfacecreated(surfaceholder holder){ }  } } 

there's not point in using 2 surfaceviews unless you've got them in separate activities. (see e.g. android breakout, uses view ui in 1 activity main menu, glsurfaceview in second activity game itself.)

since you're using surfaceview menu , game in single activity, there's no reason have 2 separate surfaceview subclasses. there's no reason subclass surfaceview @ all, really, though reason many examples continue so.

create single surfaceview, , have both mainmenupanel , gamepanel draw on it.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -