0
\$\begingroup\$
public abstract class BaseScreen  implements Screen,InputProcessor  {
    SpriteBatch batch;
    //stage principal
    protected Table uiTable;
    protected String screenAnterior;
    protected Stage mainStage;
    protected Stage uiStage;


public BaseScreen() {
    batch=new SpriteBatch();

    int vpwidth=Gdx.graphics.getWidth();
    int vpheight=Gdx.graphics.getHeight();


        mainStage = new Stage();
        uiStage = new Stage();
        Gdx.input.setInputProcessor(mainStage);
        uiTable = new Table();
        uiTable.setFillParent(true);
        uiStage.addActor(uiTable);
        initialize();
    }




    public abstract void initialize();

    public abstract void update(float dt);

    public void render(float dt) {
        //fps
        dt = Math.min(dt, 1/30f);


        uiStage.act(dt);
        mainStage.act(dt);


        batch.begin();
        batch.end();
        update(dt);


        Gdx.gl.glClearColor(0.4f, 0.5f, 0.8f, 1f);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        mainStage.draw();

     ;
    }

    public void resize(int width, int height) {}

    public void pause() {}

    public void resume() {}

    public void dispose() {}

    /**
     * Se lleva a cabo cuando la pantalla se convierte en la activa
     */
    public void show() {  

        InputMultiplexer im = (InputMultiplexer) Gdx.input.getInputProcessor();
        im.addProcessor(this);
        im.addProcessor(uiStage);
        im.addProcessor(mainStage);


    }

    /**
     * Se lleva a cabo cuando la pantalla deja de estar activa
     */
    public void hide() {  
          InputMultiplexer im = (InputMultiplexer)Gdx.input.getInputProcessor();
        im.removeProcessor(this);
        im.removeProcessor(uiStage);
        im.removeProcessor(mainStage);


    }

    public boolean keyDown(int keycode){

        return false;  
    }

    public boolean keyUp(int keycode){

        return false;
    }

    public boolean keyTyped(char c) {

        return false;
    }

    public boolean mouseMoved(int screenX, int screenY){

        return false;
    }

    public boolean scrolled(int amount) {

        return false;

    }

    public boolean touchDown(int screenX, int screenY, int pointer, int button) {

        return false;
    }

    public boolean touchDragged(int screenX, int screenY, int pointer) {

        return false;
    }

    public boolean touchUp(int screenX, int screenY, int pointer, int button) {

        return false;
    }





}

 public class Nivel1 extends BaseScreen{
     private TiledMap tviledMap;
        private OrthographicCamera tiledCamera;
        private OrthoCachedTiledMapRenderer tiledMapRenderer;
        TilemapActor tiledMapActor;
        Music song;
        Player cubo;
        MapObject startPoint;
        MapProperties startProps;

@Override
public void initialize() {

    tiledMapActor = new TilemapActor("maps/mapa2.tmx", mainStage);
    song = Gdx.audio.newMusic(Gdx.files.internal("music/TimeMachine.mp3"));
    song.setLooping(true);
    song.setVolume(0.3f);
    song.play();

    for (MapObject obj : tiledMapActor.getRectangleList("Solid") ) {

        MapProperties props = obj.getProperties();

        new Solid( (float)props.get("x"), (float)props.get("y"), (float)props.get("width"),
                (float)props.get("height"), mainStage );

    }
     startPoint = tiledMapActor.getRectangleList("inicio").get(0);

     startProps= startPoint.getProperties();
     cubo = new Player((float) startProps.get("x"), (float)startProps.get("y"), mainStage);
     for (MapObject obj : tiledMapActor.getTileList("rana")) {

         MapProperties props = obj.getProperties();
         new Rana((float)props.get("x"), (float)props.get("y"), mainStage);
     }
     for (MapObject obj : tiledMapActor.getTileList("shark")) {

         MapProperties props = obj.getProperties();
         new Shark((float)props.get("x"), (float)props.get("y"), mainStage);
     }
     for (MapObject obj : tiledMapActor.getTileList("final")) {

         MapProperties props = obj.getProperties();
         new Fin((float)props.get("x"), (float)props.get("y"), mainStage);
     }

}

@Override
public void update(float dt) {
    // TODO Auto-generated method stub

}


}

    public  class MainMenuGameScreen extends BaseScreen {

    private  Texture button;
    Skin skin;
    Skin alternativa;
    private Actorcubo prota;
    Animation animacione;
    ArrayList<Sprite>animacion;
    Music song;

    @Override
    public void initialize() {
        song = Gdx.audio.newMusic(Gdx.files.internal("music/Megalovania.mp3"));
        song.setLooping(true);
        song.setVolume(0.3f);
        //song.play();
        animacion=new ArrayList<>();
        animacion=meterSprite(animacion);

        button=new Texture("personaje0.png");
        resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        BaseActor fondo=new BaseActor(0, 0, mainStage);
        fondo.setSize(800, 640);
        crearSkins();
        alternativa=new Skin(Gdx.files.internal("craftacular/skin/craftacular-ui.json"));
        Label titulo = new Label("GEOMETRY DASH", alternativa);
        uiTable.add(titulo).center().width(250).height(75).pad(5);
        BaseActor background = new BaseActor(0, 0 , mainStage);
        //hace que escuche el stague

        TextButton button1 = new TextButton("nivel 1", skin);
        button1.addListener(new ClickListener(){
              public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                 Geometry.setActiveScreen(new Nivel1());
                }
        });



        uiTable.row();
        uiTable.add(button1).center().width(250).height(75).pad(5);
        TextButton btn2 = new TextButton("nivel 2", skin);

        btn2.addListener(new ClickListener(){
              public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                    System.out.println("nivel 2");
                }
        });

        uiTable.row();
        uiTable.add(btn2).center().width(250).height(75).pad(5);
        TextButton btn3 = new TextButton("nivel 3", skin);
        uiTable.row();

        uiTable.add(btn3).center().width(250).height(75).pad(5);
        btn3.addListener(new ClickListener(){
              public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                    System.out.println("nivel 3");
                }
        });
        TextButton btnsalir = new TextButton("salir", skin);

        btnsalir.addListener(new ClickListener() {
              @Override
                public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                    Gdx.app.exit();
                }
            });
        uiTable.row();
        uiTable.add(btnsalir).center().width(250).height(100).pad(5);
        uiTable.row();
        mainStage.addActor(uiTable);

    //  uiStage.addActor(uiTable);


    }

    private ArrayList<Sprite> meterSprite(ArrayList<Sprite> animacion2) {

        Sprite sprite1=new Sprite(new Texture(Gdx.files.internal("personaje0.png")));
        Sprite sprite2=new Sprite(new Texture(Gdx.files.internal("personaje1.png")));
        Sprite sprite3=new Sprite(new Texture(Gdx.files.internal("personaje2.png")));
        Sprite sprite4=new Sprite(new Texture(Gdx.files.internal("personaje3.png")));
    animacion2.add(sprite1);
    animacion2.add(sprite2);
    animacion2.add(sprite3);
    animacion2.add(sprite4);

        return animacion2;
    }
    private void crearSkins() {
        //creando fuente
        BitmapFont font=new BitmapFont();
        skin=new Skin();
        skin.add("default", font);
        //creando textura
        Pixmap pixmap=new Pixmap(Gdx.graphics.getWidth()/4, Gdx.graphics.getHeight()/10, Pixmap.Format.RGB888);
        pixmap.setColor(Color.WHITE);
        pixmap.fill();
        skin.add("background", new Texture(pixmap));
        //estilo del boton
        TextButton.TextButtonStyle estilo=new TextButton.TextButtonStyle();
        estilo.up=skin.newDrawable("background",Color.GRAY);
        estilo.down=skin.newDrawable("background",Color.DARK_GRAY);
        estilo.checked=skin.newDrawable("background",Color.DARK_GRAY);
        estilo.over=skin.newDrawable("background",Color.BLUE);
        estilo.font=skin.getFont("default");
        skin.add("default", estilo);

        prota=new Actorcubo(button);

        mainStage.addActor(prota);

        mainStage.addActor(uiTable);

        prota.setPosition(100, 200);

    }
\$\endgroup\$
  • 2
    \$\begingroup\$ It looks like you've shared a lot of code here that's not related to casting the InputMultiplex class. What specific problem have you encountered with this action? Please edit your question to contain a complete description of what you're trying to do and what's going wrong. \$\endgroup\$ – DMGregory May 12 at 16:08

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.