【问题标题】:LibGDX splicing up texture fileLibGDX拼接纹理文件
【发布时间】:2016-02-13 22:26:36
【问题描述】:

我有一个图像,它由块 (32*32) 组成,有 1 行和 4 列。我该怎么做,当我加载纹理时,我只加载一个块而不是全部 4 个?

【问题讨论】:

  • 你是想在内存中实际只加载这个特定的块,还是只使用这个特定的块作为精灵中的纹理?
  • 作为使用精灵批处理渲染的纹理。

标签: libgdx textures


【解决方案1】:

方法一)

    Texture texture=new Texture(Gdx.files.internal("ui/logo2.png"));
    Sprite sprite=new Sprite(texture);
    sprite.setRegion(0, 0, 1f/4f, 1);//this loads the first block
    sprite.setRegion(1f/4f, 0, 1f/4f+1f/4f, 1);//this loads the second block
    sprite.setRegion((1f/4f)*2, 0, 1f/4f+(1f/4f)*2, 1);//this loads the third block
    //on render
    sprite.draw(theSpriteBatch);   

方法二)

    Texture texture=new Texture(Gdx.files.internal("ui/logo2.png"));
    TextureRegion[][] tmp = TextureRegion.split(texture, 32, 32);
    Sprite sprite=new Sprite(tmp[0][0]);//first
    Sprite sprite=new Sprite(tmp[0][1]);//second
    Sprite sprite=new Sprite(tmp[0][2]);//third
    //on render
    sprite.draw(yourSpriteBatch);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-16
    • 2013-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多