java - Can't switch screen [Libgdx] -


i'm new libgdx , can't figure out wrong. in game want switch between 2 screens (first menuscreen, second gamescreen). have created these 2 screens , 1 game class, looks okay. when call method setscreen(new gamescreen()) nothing happens. should say, used screen , game classes in previous project , ok, when compare current code previous 1 not see differences, curiously.

here menuscreen class:

menuscreen implements screen {  private spritebatch batch ; private texture texture; private float timepassed;   public menuscreen() {     timepassed = 0;     batch = new spritebatch();     texture = new texture("texture.png");  @override public void render (float delta) {     timepassed += gdx.graphics.getdeltatime();     gdx.gl.glclearcolor(1, 0, 0, 1);     gdx.gl.glclear(gl20.gl_color_buffer_bit);     if (timepassed > 5) {gameclass.getinstance().setscreen(new gamescreen());} //it looks strange, it's check if works     batch.begin();     batch.draw(texture, 0, 0);     batch.end(); }  @override public void dispose() {     batch.dispose();     texture.dispose(); }  @override public void hide() {  }  @override public void resume() {  }  @override public void pause() {  }  @override public void resize(int width, int height) {  }  @override public void show() {  }} 

here gamescreen class:

gamescreen implements screen {  private spritebatch batch2 ; private texture texture2;   public menuscreen() {     batch2 = new spritebatch();     texture2 = new texture("texture2.png"); } @override public void render (float delta) {     gdx.gl.glclearcolor(1, 0, 0, 1);     gdx.gl.glclear(gl20.gl_color_buffer_bit);     batch2.begin();     batch2.draw(texture2, 0, 0);     batch2.end(); }  @override public void dispose() {     batch2.dispose();     texture2.dispose(); }  @override public void hide() {  }  @override public void resume() {  }  @override public void pause() {  }  @override public void resize(int width, int height) {  }  @override public void show() {  }} 

and game class:

public class classgame extends game { public static classgame getinstance(){     classgame instance = new classgame();     return instance; } @override public screen getscreen() {     return super.getscreen(); }  @override public void setscreen(screen screen) {     super.setscreen(screen); } @override public void resize(int width, int height) {     super.resize(width, height); }  @override public void render() {     super.render(); }  @override public void resume() {     super.resume(); }  @override public void pause() {     super.pause(); }  @override public void dispose() {     super.dispose(); }  public classgame() {     super(); }  @override public void create() {     menuscreen menuscreen = new menuscreen();     setscreen(menuscreen); }} 

this how did same problem, had 3 classes 2 screen switch between them. here switching between second , third using image actor button.i used 2 constructors in each class, 1 of them constructors no arguments, below code hope it. main class code:

public class first extends game{ private game game; public main(){ game=this; } public void create() {     game.setscreen(new second(game)); }} 

below first screen class code

public class second implements screen{ private game second; public second(game second){this.second=second;} public second(){} // code stage mystage=new stage(new screenviewport()); group mygroup=new group(); image secondbutton=new image(new texture(gdx.files.internal("image.png"))); public void show(){     mygroup.addactor(secondbutton);     secondbutton.addlistener(new inputlistener(){     second.setscreen(new third(second)); });} public void render(float delta) {     gdx.gl.glclear(gl20.gl_color_buffer_bit);     mystage.act(gdx.graphics.getdeltatime());      mystage.draw(); } public void resize(int width, int height) {} public void pause(){} public void resume(){} public void hide(){} public void dispose(){}}} 

and next screen class code

 public class third implements screen{ private game third; public third(game third){     this.third=third;} public third(){} // code stage mystage=new stage(new screenviewport()); group mygroup=new group(); image thirdbutton=new image(new texture(gdx.files.internal("image.png"))); public void show() {     mygroup.addactor(thirdbutton);     thirdbutton.addlistener(new inputlistener(){         third.setscreen(new third(third));});} public void render(float delta) {     gdx.gl.glclear(gl20.gl_color_buffer_bit);     mystage.act(gdx.graphics.getdeltatime());     mystage.draw();} public void resize(int width, int height) {    } public void pause(){} public void resume(){} public void hide(){} public void dispose(){}}} 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -