【问题标题】:Getting error trying to load a sprite from a skin.json尝试从 skin.json 加载精灵时出错
【发布时间】:2014-04-09 15:53:03
【问题描述】:

我正在尝试从 skin.json 加载 libgdx 中的简单皮肤。皮肤文件非常简单:

{        
    com.badlogic.gdx.graphics.g2d.Sprite : {
            centerImage : {

            }
        }
}

使用此代码,代码运行良好,但我得到一个空精灵。尝试加载纹理并加载纹理化的精灵,加载纹理时出现异常:

{
    com.badlogic.gdx.graphics.Texture : {
        centerImageTexture : {
            file : images/crop001.png
        }
    },

    com.badlogic.gdx.graphics.g2d.Sprite : {
        centerImage : {
            texture : centerImageTexture
        }
    }
}

这是 libGDX 代码

 skin = new Skin(Gdx.files.internal(skinFile));

centralImage = skin.getSprite("centerImage");

我需要一种在不使用图集的情况下将纹理定义到皮肤文件中的方法。文档解释了如何加载纹理:

Texture texture = skin.get("logo", Texture.class);

但我找不到定义它的方法

谢谢!!

【问题讨论】:

  • 我认为您可以通过调试轻松找到原因
  • 我想我知道发生了什么。我将问题编辑得更清楚。

标签: java libgdx


【解决方案1】:

如果你想使用

Texture texture = skin.get("logo", Texture.class);

get-Method 在 uiskin.atlas 中搜索,而不是在 uiskin.json 中搜索。应该有一个名为“logo”的条目:

logo
  rotate: false
  xy: 170, 44
  size: 100, 100
  orig: 100, 100
  offset: 0, 0
  index: -1

您可以根据需要使用此代码 sn-p。根据您的需要修改 xy 的参数(uiskin.png 中 TextureRegion 的左上角和 sizeorigin (您的TextureRegion in Pixel)。大小和原点应该是一样的。其他参数你可以照原样。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-30
    相关资源
    最近更新 更多