LWJGL,Slick Util,2d渲染精灵,没有背景

时间:2017-01-21 11:45:56

标签: java background lwjgl

如何渲染没有背景的精灵?我能够渲染整个精灵,但我想忽略背景。我知道这是可能的,因为我在Tibia看到了那种渲染。胫骨中的精灵具有粉红色背景,被忽略 精灵:

public class Sprite {

private Texture texture;


private float sx;
private float sy;
private String extension;
private String path;


/**
 *
 * @param sx
 * @param sy
 * @param extension
 * @param path
 */
public Sprite(float sx, float sy, String extension, String path) {

    this.sx = sx;
    this.sy = sy;
    this.extension = extension;
    this.path = path;
}


public void render() {

    try {
        initTexture();

    } catch (Exception e) {
        System.out.println(e.toString());
    }
    Color.white.bind();
    texture.bind();
    glBegin(GL_QUADS);


    glTexCoord2f(0, 0);
    glVertex2f(0, 0);
    glTexCoord2f(0, 1);
    glVertex2f(0, texture.getTextureHeight()*2);
    glTexCoord2f(1, 1);
    glVertex2f(texture.getTextureWidth()*2, texture.getTextureHeight()*2);
    glTexCoord2f(1, 0);
    glVertex2f(texture.getTextureWidth()*2, 0);


    glEnd();


}

public float getSx() {
    return sx;
}

public void setSx(float sx) {
    this.sx = sx;
}

public float getSy() {
    return sy;
}

public void setSy(float sy) {
    this.sy = sy;
}

public void initTexture() throws Exception {

    texture = TextureLoader.getTexture(extension, ResourceLoader.getResourceAsStream(path));


}

}

1 个答案:

答案 0 :(得分:0)

我猜你正试图为你的游戏使用一个瓦片组,它有一个紫色网格。

我建议你用透明度替换粉红色。 然后,在你的程序中,只需:

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

紫色TileSets / SpriteSheets用于较旧的游戏。没有实际需要。

相关问题