Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在LibGDX中将一个屏幕移动到另一个屏幕。?_Java_Android_Libgdx - Fatal编程技术网

Java 如何在LibGDX中将一个屏幕移动到另一个屏幕。?

Java 如何在LibGDX中将一个屏幕移动到另一个屏幕。?,java,android,libgdx,Java,Android,Libgdx,我正在尝试使用LIBGDX游戏引擎将一个屏幕移动到另一个屏幕。 我的第一个屏幕上我有一个按钮,我想当我点击这个按钮屏幕应该是改变 package com.mygdx.game; import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graph

我正在尝试使用LIBGDX游戏引擎将一个屏幕移动到另一个屏幕。 我的第一个屏幕上我有一个按钮,我想当我点击这个按钮屏幕应该是改变

package com.mygdx.game;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;


public class MyGdxGame extends Game implements Screen,InputProcessor{
Stage stage;
TextureRegion rgn_reply;
TextButton button_reply;
TextButtonStyle reply_style;
BitmapFont font;

Game game;
Screen1 screen1;
MyGdxGame h;
float y_touched;
float x_touched;
public MyGdxGame()
{

}
public MyGdxGame(Game _g)
{
    this.game=_g;
}
@Override
public void create() {
    // TODO Auto-generated method stub

    font = new BitmapFont();


    stage = new Stage();
    Sprite sp_button =  new Sprite(new TextureRegion(new Texture("whats-app.png")));
    Sprite sp_button_active =  new Sprite(new TextureRegion(new Texture("whats-app_active.png")));
    reply_style = new TextButtonStyle(new TextureRegionDrawable(sp_button),new TextureRegionDrawable(sp_button_active),null,font);
    button_reply = new TextButton("", reply_style);
    button_reply.setPosition(55,55);
    button_reply.setSize(100, 100);
    stage.addActor(button_reply);
    Gdx.input.setInputProcessor(stage);
    button_reply.addListener(new ClickListener() {
           @Override
           public void clicked(InputEvent event, float x, float y) {
               System.out.println("button clicked");
               game.setScreen(new Screen1());
             };
       });

}
 @Override
    public void render() {
        Gdx.gl.glClearColor(0.18f,0.21f,0.27f, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        super.render();
        stage.draw();
    }
@Override
public boolean keyDown(int keycode) {
    // TODO Auto-generated method stub
    return false;
}
@Override
public boolean keyUp(int keycode) {
    // TODO Auto-generated method stub
    return false;
}
@Override
public boolean keyTyped(char character) {
    // TODO Auto-generated method stub
    return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    // TODO Auto-generated method stub

    return false;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
    // TODO Auto-generated method stub
    return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
    // TODO Auto-generated method stub
    return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
    // TODO Auto-generated method stub

    return false;
}
@Override
public boolean scrolled(int amount) {
    // TODO Auto-generated method stub
    return false;
}
@Override
public void render(float delta) {
    // TODO Auto-generated method stub

}
@Override
public void show() {
    // TODO Auto-generated method stub

}
@Override
public void hide() {
    // TODO Auto-generated method stub

}
}
这是我的第二个屏幕代码,屏幕上没有任何内容

package com.mygdx.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;

public class Screen1 implements Screen{

MyGdxGame h;

public Screen1(MyGdxGame _h)
{
    this.h=_h;
}

public Screen1()
{

}

@Override
public void render(float delta) {
    // TODO Auto-generated method stub
    Gdx.gl.glClearColor(0.18f,0.21f,0.27f, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
}

@Override
public void resize(int width, int height) {
    // TODO Auto-generated method stub

}

@Override
public void show() {
    // TODO Auto-generated method stub

}

@Override
public void hide() {
    // TODO Auto-generated method stub

}

@Override
public void pause() {
    // TODO Auto-generated method stub

}

@Override
public void resume() {
    // TODO Auto-generated method stub

}

@Override
public void dispose() {
    // TODO Auto-generated method stub

}

}

这不能正常工作。不显示第二个屏幕。

您可以查看以下链接:

  • game.setScreen(新屏幕1(您的游戏))行中


    为什么?向下投票我的答案,我认为它应该解释向下投票,1因为假设它有,向下投票,有一个正确的解决方案,可以公布你的答案,如果不是这样,可以说那是什么,我的答案是错误的,感谢阅读错误是什么?
        //Other Code
    
        @Override
        public void clicked(InputEvent event, float x, float y) {
               System.out.println("button clicked");
               game.setScreen(new Screen1(game));
        };
    
        //Other Code