【发布时间】:2015-08-02 07:47:01
【问题描述】:
我正在编写一个新的 3D 游戏并使用运行良好的 FirstPersonCameraController(子类)。然后我检测我是否在移动设备上并将一些 TextButton 添加到舞台上。这些出现但不能按下?
public ControlsController(Camera camera, GameRenderScreen gameRenderScreen, Stage stage) {
super(camera);
this.gameRenderScreen = gameRenderScreen;
// create control
if (Gdx.app.getType() == Application.ApplicationType.Android || Gdx.app.getType() == Application.ApplicationType.iOS)
{
forwardButton = new TextButton("Forward", Gui.getSkin());
forwardButton.setBounds(width() - 130, 130, 80, 50);
stage.addActor(forwardButton);
leftButton = new TextButton("Left", Gui.getSkin());
leftButton.setBounds(width() - 170, 70, 70, 50);
stage.addActor(leftButton);
rightButton = new TextButton("Right", Gui.getSkin());
rightButton.setBounds(width() - 80, 70, 70, 50);
stage.addActor(rightButton);
backwardButton = new TextButton("Backward", Gui.getSkin());
backwardButton.setBounds(width() - 130, 10, 80, 50);
stage.addActor(backwardButton);
}
InputMultiplexer multiplexer = new InputMultiplexer();
multiplexer.addProcessor(stage);
Gdx.input.setInputProcessor(multiplexer);
}
// 这是通过主渲染循环调用的
public void updateControls(){
if (Gdx.app.getType() == Application.ApplicationType.Android || Gdx.app.getType() == Application.ApplicationType.iOS) {
if (forwardButton.isPressed()) {
keyDown(Input.Keys.W);
}
if (backwardButton.isPressed()) {
keyDown(Input.Keys.S);
}
if (leftButton.isPressed()) {
keyDown(Input.Keys.A);
}
if (rightButton.isPressed()) {
keyDown(Input.Keys.D);
}
}
}
// 更新相机
public void update(){
fps.update();
fps.updateControls();
camera.position.set(camera.position.x, 0.0f, camera.position.z);
}
// 更新渲染循环
@Override
public void render(float delta) {
update();
Gdx.gl20.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
//TODO do we need all of these?
//Do all your basic OpenGL ES setup to start the screen render.
Gdx.gl20.glClearColor(0.0f, 0.3f, 0.5f, 1);
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl20.glEnable(GL20.GL_TEXTURE_2D);
Gdx.gl20.glEnable(GL20.GL_BLEND);
Gdx.gl20.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
Gdx.gl20.glCullFace(GL20.GL_BACK);
Gdx.gl20.glEnable(GL20.GL_DEPTH_TEST);
// Like spriteBatch, just with models! pass in the box Instance and the environment
modelBatch.begin(camera);
Skybox.update(camera.position);
modelBatch.render(Skybox.modelInstance);
for (int i = 0; i < boxInstance.size; i ++ ) {
modelBatch.render(boxInstance.get(i));
}
modelBatch.end();
//TODO Whats this for
stage.getViewport().update(width(), height(), true);
stage.act(delta);
stage.draw();
drawFPS();
}
【问题讨论】:
-
您是否在渲染循环中调用
stage.act()? -
是的(必须检查:)),我将我的渲染循环发布到:)
-
如果你在
Stage.touchDown()添加断点,调试器会说什么?