libgdx使用texturepacker显示背景

时间:2015-02-09 16:53:51

标签: libgdx texturepacker

我的图像背景大小为480 * 800.我使用texturepacker来创建.pack文件。 我尝试在屏幕上显示背景,但背景显示非常小,不适合屏幕设备。请帮我正确显示背景。感谢

1 个答案:

答案 0 :(得分:0)

您只需调整图片的大小:

 private SpriteBatch spriteBatch;
 private Texture texture; 
 private Sprite textureSprite;

   public void show(){ // It might also be called create(); 
   spriteBatch = new SpriteBatch();
   texture = new Texture(Gdx.files.internal("location of img in assets folder"));
   textureSprite = new Sprite(texture);

   //Set the image width/height to the width/height of the screen.
   textureSprite.setBounds(0,0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
 } 
 public void render(float delta) {
     Gdx.gl.glClearColor(0, 0, 0, 1);
     Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
     // Clear the screen every loop

     spriteBatch.begin();
     textureSprite.draw(spriteBatch);
     spriteBatch.end();

}