내 LibGdx Java 게임에 여러 개의 스크린을 사용하고 있는데 배경을 렌더링하는 시작 화면과 죽음 화면을 가져 오는 데 문제가 있습니다. 내가 선택한 것처럼 백그라운드가 올바른 위치에 있습니다. Main.java (게임 자체)는 작동하지만 그 밖의 것은 없습니다. 시작과 끝 화면에서 작동하는 유일한 것은 키보드 입력과 같은 입력입니다.LibGdx 배경이 렌더링되지 않습니다.
코드 : FishGame.java
package us.webco.fish;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class FishGame extends Game {
public SpriteBatch batch;
public void create() {
batch = new SpriteBatch();
this.setScreen(new StartScreen(this));
}
public void render() {
super.render();
}
public void dispose() {
batch.dispose();
}
}
StartScreen.java (빈 함수는 잘라)
package us.webco.fish;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
public class StartScreen implements Screen{
private Texture backgroundImage;
private Sprite backgroundToSprite;
final FishGame game;
public StartScreen(final FishGame gam) {
game = gam;
backgroundImage = new Texture(Gdx.files.internal("../android/assets/startScreen.jpg"));
backgroundToSprite = new Sprite(backgroundImage);
backgroundToSprite.setSize(Main.width, Main.height);
}
@Override
public void render(float p) {
p = 1/60f; /* FPS */
Gdx.gl.glClearColor(0.4f,0.4f,0.7f,1.0f); /* Setting a default background color */
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); /* Rendering purposes */
game.batch.begin();
game.batch.draw(backgroundToSprite, Main.width, Main.height);
game.batch.end();
if(Gdx.input.isKeyPressed(Keys.X)) {
System.out.println("Start Game");
game.setScreen(new Main(game));
dispose();
}
if(Gdx.input.isKeyPressed(Keys.Z)) {
System.out.println("Game has been quit!");
Gdx.app.exit();
}
}
Main.java도 game.batch를 사용합니다. LibGdx 튜토리얼을 따라갈 때 왜 작동하지 않는지 잘 모르겠습니다. 미리 감사드립니다.
고맙습니다. 나는 그것을 실제로했다라고 생각할 수 없다, 하하! –