Slick2d Spritesheet showing whole image

Posted by BotskoNet on Game Development See other posts from Game Development or by BotskoNet
Published on 2013-09-18T23:39:33Z Indexed on 2013/10/19 10:16 UTC
Read the original article Hit count: 310

Filed under:
|

I'm trying to show a single subimage from a sprite sheet. Using slick2d SpriteSheet class, all it's doing is showing me the entire image, but scaled down to fit the cell dimensions.

The image is 96x192 and should have cells of 32x32.

The code:

SpriteSheet spriteSheet = new SpriteSheet("images/"+file, 32, 32 );

System.out.println("Horiz Count: " + spriteSheet.getHorizontalCount());
System.out.println("Vert Count: " + spriteSheet.getVerticalCount());
System.out.println("Height: " + spriteSheet.getHeight());
System.out.println("Width: " + spriteSheet.getWidth());
System.out.println("Texture Width: " + spriteSheet.getTextureWidth());
System.out.println("Texture Height: " + spriteSheet.getTextureHeight());

Prints:

Horiz Count: 3
Vert Count: 6
Height: 192
Width: 96
Texture Width: 0.75
Texture Height: 0.75

Not sure what the texture dimensions refer to, but the rest is entirely accurate. However, when I draw the icon, the entire sprite image shows scaled down to 32x32:

    Image image = spriteSheet.getSprite(1, 0); // a test
image.bind();

GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0,0);
    GL11.glVertex2f(x,y);
    GL11.glTexCoord2f(1,0);
    GL11.glVertex2f(x+image.getWidth(),y);
    GL11.glTexCoord2f(1,1);
    GL11.glVertex2f(x+image.getWidth(),y+image.getHeight());
    GL11.glTexCoord2f(0,1);
    GL11.glVertex2f(x,y+image.getHeight());
GL11.glEnd();
GL11.glDisable(GL11.GL_BLEND);

© Game Development or respective owner

Related posts about java

Related posts about slick