使用Slick-UTIL和LWJGL从纹理ID中获取纹理

时间:2020-10-07 01:21:22

标签: java lwjgl

我正在为正在开发的游戏使用LWJGL 2和slick-utils。当我创建一个可渲染对象时,我从中存储纹理ID

Entity entity = new Entity();  // My Entity class
Texture entityTexture = getTexture("textureFile.png");  // Slick-util's Texture class
int textureID = entityTexture .getTextureID();
entity.setTextureID(textureID);  // Stores the textureID so I can use it with LWJGL later on
实体对象中的

。我不存储纹理本身。如果我有2个使用相同纹理的实体并打印出它们的textureID,则两个实体的编号将不同。当然,这会导致更大范围的性能损失。如果2个实体具有相同的Texture,我希望它们也具有相同的textureID。是否可以从Texture获取textureID对象,所以我可以做类似的事情:

List<Entity> entities = new ArrayaList<Entity>;  // Stores all renderable entities

Entity entity1 = new Entity();  // New Entity
entities.add(entity1 );  // Adds entity to list for rendering
Texture entityTexture = getTexture("textureFile.png");  // Gets the texture
int textureID = entityTexture .getTextureID();  // Gets the textureID

for (Entity entity : entities) {
    // Pretend entities list is filled with many Entities using the same Texture
    // These will result in ID's such as 1 & 2 -- Different numbers, same Texture
    int testID = entity.getTextureID();  // Stores the textureID of the entity I'm testing against
    int currentID = entity1.getTextureID();  // Stores the textureID of entity1, the Entity being added
    Texture testTexture = TextureLoader.getTextureFromID(testID);  // Pretend function of what I'm potentially looking for
    Texture currentTexture= TextureLoader.getTextureFromID(currentID );  // Gets the texture associated with ID currentID(possibly 2 or something)
    if (testTexture == currentTexture) {
        // I know the textures are the same and I can use the same ID for both
    }
}

或者我应该只一般地存储纹理并比较它们以获取textureID吗?

0 个答案:

没有答案