我在我的LibGdx Java游戏中使用了多个屏幕,我在获得开始屏幕和死亡屏幕渲染背景时遇到了困难。背景在正确的地方,我已经检查过了。Main.java (游戏本身)工作,但没有其他。在“开始”和“死亡”屏幕上唯一工作的是输入,比如键盘输入。
代码: 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教程,谢谢提前。
发布于 2014-11-20 17:15:14
尝尝这个
backgroundImage = new Texture(Gdx.files.internal("startScreen.jpg"));编辑:spriteBatch.draw(.,plaction.x,plaction.y);
您使用的位置宽度和高度,没有超出屏幕。
发布于 2014-11-21 01:15:27
你把相机的位置调对了吗?
您是否更新相机并将投影矩阵设置为您的SpriteBatch?
https://stackoverflow.com/questions/27044112
复制相似问题