Java 将纹理粘贴为背景libgdx

Java 将纹理粘贴为背景libgdx,java,opengl,libgdx,2d,Java,Opengl,Libgdx,2d,我正在尝试将一个png文件粘贴到屏幕上作为我游戏的背景,到目前为止,我似乎无法让它工作,我也不太确定 我创建了一个贴图类,并让它创建纹理,如下所示: public static Texture backgroundTexture; public static Sprite backgroundSprite; public Maps(){ try{ backgroundTexture = new Texture(Gdx.files.internal("backgroun

我正在尝试将一个png文件粘贴到屏幕上作为我游戏的背景,到目前为止,我似乎无法让它工作,我也不太确定

我创建了一个贴图类,并让它创建纹理,如下所示:

public static Texture backgroundTexture;
public static Sprite backgroundSprite;


public Maps(){
    try{
        backgroundTexture = new Texture(Gdx.files.internal("background.png"));
        backgroundSprite = new Sprite(backgroundTexture);
    }catch (Exception e){
        e.printStackTrace();
    }
}

public void renderBackground(SpriteBatch batch){
    batch.draw(backgroundTexture, 1000, 800);
}
然后在我的主类中,我在create方法中这样调用它:

batch = new SpriteBatch();
map = new Maps();
    batch.begin();
    map.renderBackground(batch);
    batch.end();
batch.setProjectionMatrix(cam.combined);
batch.begin();
map.renderBackground(batch);
batch.end();
但这不管用?它是否应该在渲染方法中,因为它需要每次刷新背景?我在渲染中尝试过,但仍然不起作用。我的屏幕大小是WXH 1000x800

试试这个:

OrthographicCamera cam = new OrthographicCamera(1000, 800);
SpriteBatch batch = new SpriteBatch();
Maps map = new Maps();
在渲染/更新方法中:

batch = new SpriteBatch();
map = new Maps();
    batch.begin();
    map.renderBackground(batch);
    batch.end();
batch.setProjectionMatrix(cam.combined);
batch.begin();
map.renderBackground(batch);
batch.end();
在“贴图”渲染方法中:

batch.draw(backgroundTexture, 0, 0, 1000, 800); //x, y, width, height

该行的batch.DruckGroundTexture,1000800;X和Y的参数是纹理左下角的位置。我想你可能想使用0,0或者-screenWidth/2,-screenHeight/2,这取决于你的相机是如何设置的。你不是在你的雪碧批次中使用相机吗?如果不是,它会将屏幕尺寸视为2x2。@这是OpenGL的默认值。如果在顶点着色器中不变换顶点位置,或者如果变换矩阵与SpriteBatch中的相同,如果保持不变,则所有内容都映射到-1,-1到1,1。这很好,但我无法再看到所有图形和内容。现在是不是贴在上面了?修正了,是因为我应该在抽签前打电话给玩家!这成功了!谢谢你!