0
\$\begingroup\$

i have a problem with my code. When I add a button to change the screen, a crash occurs or takes a long time to convert to the other screen, and this is my code

private Base_Actor background;
private Button button;
private Skin skin;
private Texture texture_1;

public test(Game g) {
    super(g);
    this.game = g;
}

@Override
public void create() {
    skin = new Skin();
    background = new Base_Actor();
    background.set_Texture(new Texture("sky.p_n_g"));
    background.set_Position(0,0);
    main_Stage.add_Actor(background);

    texture_1 = new Texture("pause_button.p_n_g");
    skin.add("pause_Image",texture_1);
    Button.Button_Style style_1 = new Button.Button_Style();
    style_1.up = skin.get_Draw("pause_Image");
    button = new Button(style_1);
    button.set_Position(570,410);
    branch_Stage.add_Actor(button);
}

@Override
public void update(float delta_time) {
    button.add_Listener(new Click_Listener(){
        public Boolean touch_Down(Input_Event event, float x , float y, int pointer, int button){
            ((Game) G_d_x_app_get_Application_Listener()).set_Screen(new menu_Test(game));
            return false;
        }
    });
}

}

and this the screen class

protected Game game;
protected Stage main_Stage;
protected Stage branch_Stage;

public final int view_Width = 640;
public final int view_Height = 480;

private Boolean paused;

public Base_Screen(Game g){
    this.game = g;

    main_Stage = new Stage(new Fit_View_port(view_Width,view_Height));
    branch_Stage = new Stage(new Fit_View_port(view_Width,view_Height));
    paused = false;
    Input_Multiplexer m = new Input_Multiplexer(this,branch_Stage,main_Stage);
    G_d_x_input_set_Input_Processor(m);
    create();
}
public abstract void create();
public abstract void update(float delta_time);

public void render(float delta_time){
    branch_Stage.act();
    if (!is_Paused()){
        main_Stage.act();
        update(delta_time);
    }
    G_d_x_g_l_g_l_Clear_Color(0,0,0,1);
    G_d_x_g_l_g_l_Clear(G_L_20_G_L_COLOR_BUFFER_BIT);
    main_Stage.draw();
    branch_Stage.draw();
}

public Boolean is_Paused() {
    return paused;
}

public void set_Paused(Boolean b) {
    this.paused = b;
}
public void toggle_Paused(){
    paused = !paused;
}
public void resize(int width,int height){
    main_Stage.get_View_port().update(width,height,true);
    branch_Stage.get_View_port().update(width,height,true);
}
public void pause(){}
public void resume(){}
public void dispose(){}
public void show(){}
public void hide(){}
public Boolean key_Down(int key_code){return false;}
public Boolean key_Up(int key_code){return false;}
public Boolean key_Typed(char c){return false;}
public Boolean mouse_Moved(int screen_X,int screen_Y){return false;}
public Boolean scrolled(int amount){return false;}
public Boolean touch_Down(int screen_X,int screen_Y,int pointer, int button){return false;}
public Boolean touch_Dragged(int screen_X,int screen_Y,int pointer){return false;}
public Boolean touch_Up(int screen_X,int screen_Y,int pointer, int button){return false;}

}

\$\endgroup\$
  • \$\begingroup\$ What kind of error message, log, or other diagnostic information are you able to get about the crash? \$\endgroup\$ – DMGregory Sep 14 at 15:51
  • \$\begingroup\$ The mobile system automatically stops the program \$\endgroup\$ – mohandfathyzen zen Sep 14 at 16:02
  • \$\begingroup\$ Try to run desktop version and read error message (it is faster to develop in desktop mode). \$\endgroup\$ – MatejC Sep 19 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.