0
我想在同一個屏幕上有兩個階段,但問題是,第二階段(static_stage)的輸入監聽器沒有響應,但沒有問題在繪製它的actors.the第一階段(舞臺)工作並且響應良好。這裏是代碼,請告訴我我哪裏錯了?輸入監聽器在第二階段不工作在libgdx
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();
}
}