【问题标题】:input listener in second stage not working in libgdx第二阶段的输入侦听器在 libgdx 中不起作用
【发布时间】:2014-08-04 23:12:51
【问题描述】:

我想在同一个屏幕上有两个阶段,但问题是,第二阶段(static_stage)的输入侦听器没有响应,但在绘制其演员时没有问题。第一阶段(阶段)工作并且响应良好.这是代码,请告诉我哪里出错了?

package com.amal.arrange;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;

public class gamescreen implements Screen {

final Mygame game;
OrthographicCamera camera;
Texture background;
Sprite sprite_back;
Stage stage;
Stage static_stage;
Label shuffle;
LabelStyle shuffle_style;
BitmapFont shuffle_font;


public gamescreen(final Mygame Game) {
    game = Game;
    camera = new OrthographicCamera();
    camera.setToOrtho(false, Gdx.graphics.getWidth(),
            Gdx.graphics.getHeight());
    stage=new Stage();
    static_stage=new Stage(stage.getViewport(),stage.getSpriteBatch());
    static_stage.clear();
    stage.clear();

    Gdx.input.setInputProcessor(stage);
    Gdx.input.setInputProcessor(static_stage);

    Tile_manager.load();

}

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(0.85f, 0.85f, 0.85f, 0.85f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    camera.update();
    game.batch.setProjectionMatrix(camera.combined);
    game.batch.begin();
    game.batch.draw(sprite_back, 0, 0);
    game.batch.end();

    stage.draw();
    static_stage.draw();



}

@Override
public void resize(int width, int height) {
    static_stage.getViewport().update(width, height, true);
    stage.getViewport().update(width, height, true);

}

@Override
public void show() {
    //System.out.println("in show");
    background=new Texture(Gdx.files.internal("background/background.png"));
    sprite_back=new Sprite(background);
    sprite_back.setBounds(0, 0, background.getWidth(), background.getHeight());
    Tile_manager.generate_tile();
    Tile_manager.add_listener();
    stage=Tile_manager.get_tile_stage();

    shuffle_font=new BitmapFont(Gdx.files.internal("fonts/shuffle.fnt"), false);
    shuffle_style=new LabelStyle(shuffle_font, null);
    shuffle=new Label("SHUFFLE", shuffle_style);
    shuffle.setPosition(190, 1330);

    shuffle.addListener(new InputListener(){
        @Override
        public boolean touchDown(InputEvent event, float x, float y,
                int pointer, int button) {
            System.out.println("in down");
            return true;
        }
        @Override
        public void touchUp(InputEvent event, float x, float y,
                int pointer, int button) {
            System.out.println("in up");

        }
    });


    static_stage.addActor(shuffle);

}





@Override
public void hide() {

}

@Override
public void pause() {

}

@Override
public void resume() {

}

@Override
public void dispose() {
    background.dispose();
    stage.dispose();
}

 }

【问题讨论】:

    标签: listener actor stage


    【解决方案1】:

    我也面临同样的问题。但首先,你把输入监听器弄得一团糟, 你必须设置一个输入多路复用器来管理两个输入

    InputMultiplexer inputMultiplexer = new InputMultiplexer();
    inputMultiplexer.addProcessor(stage);
    inputMultiplexer.addProcessor(static_stage);
    Gdx.input.setInputProcessor(inputMultiplexer);
    

    但不确定这是否足够......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-17
      • 2012-04-01
      • 1970-01-01
      • 2014-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-11
      相关资源
      最近更新 更多