【问题标题】:libgdx display background using texturepackerlibgdx 使用 texturepacker 显示背景
【发布时间】:2015-02-09 16:53:50
【问题描述】:

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

【问题讨论】:

  • 方法太多了,有代码例子吗?
  • 问题不在于纹理打包器,问题在于您对 libgdx 的了解。寻找好的教程。我敢打赌,你的相机设置是错误的。请记住:没有代码 - 没有真正的帮助。
  • 谢谢大家。我发现问题是视口设置不正确

标签: libgdx texturepacker


【解决方案1】:

您只需要简单地调整图像的大小:

 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();

}

【讨论】:

    猜你喜欢
    • 2016-08-19
    • 2016-05-16
    • 1970-01-01
    • 2012-10-30
    • 2014-03-20
    • 2015-08-31
    • 1970-01-01
    • 1970-01-01
    • 2018-08-02
    相关资源
    最近更新 更多