我制作了我的第一个游戏,当主要演员被击中时,游戏画面显示出来了。
我的启动课
public class MenuScreen implements Screen {
private GameState currentState;
Skin skin;
Stage stage;
SpriteBatch batch;
Game g;
public MenuScreen(Game g){
create();
this.g=g;
}
...
textButton.addListener(new ChangeListener() {
public void changed (ChangeEvent event, Actor actor) {
//System.out.println("Clicked! Is checked: " + button.isChecked());
textButton.setText("Starting new game");
g.setScreen( new GameScreen());
}
});
MenuScreen.class
public class GameScreen implements Screen {
private GameWorld world;
private GameRenderer renderer;
private float runTime;
MyGdxGame game;
public GameScreen(){
game = new MyGdxGame();
float screenWidth = Gdx.graphics.getWidth();
float screenHeight = Gdx.graphics.getHeight();
float gameWidth = 600;
float gameHeight = screenHeight / (screenWidth / gameWidth);
int midPointY = (int) (gameHeight / 2);
int midPointX = (int) (gameWidth /2);
world = new GameWorld();
renderer = new GameRenderer(world, (int) gameHeight, midPointY);
Gdx.input.setInputProcessor(new InputHandler(world.getNinja()));
}
@Override
public void render(float delta) {
runTime += delta;
world.update(delta);
renderer.render(runTime);
if(world.ninjaDead == true){
game.setScreen(new GameOver(game));
...
GameScreen.class
public class GameOver implements Screen{
private GameState currentState;
Skin skin;
Stage stage;
SpriteBatch batch;
MyGdxGame game;
int scores;
public GameOver(MyGdxGame game) {
this.game = game;
create();
Gdx.app.log("startGameOver", "");
....
public void render (float delta) {
Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));
stage.draw();
// Table.drawDebug(stage);
}
和GameOver.class
08-14 20:01:55.775 2038-2047/com.spiralaxis.citiconnect E/StrictMode﹕ A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:184)
at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:287)
at com.android.org.conscrypt.OpenSSLSocketImpl.waitForHandshake(OpenSSLSocketImpl.java:623)
at com.android.org.conscrypt.OpenSSLSocketImpl.getSession(OpenSSLSocketImpl.java:787)
at com.firebase.tubesock.WebSocket.verifyHost(WebSocket.java:333)
at com.firebase.tubesock.WebSocket.createSocket(WebSocket.java:319)
at com.firebase.tubesock.WebSocket.run(WebSocket.java:117)
基本上GameOver类正在启动,因为日志显示“startGameOver”但屏幕显示我的游戏(GameScreen)移动仅输入停止工作。我的事情我喊停止渲染GameScreen,清除屏幕,但我不知道如何?