Hello Guest

spritesheet binding

  • 3 Replies
  • 6247 Views
spritesheet binding
« on: February 24, 2012, 16:07:51 »
hello people. i have a problem with binding sprites.

the sprite atlas size i want to load is 64x32 pixels and contains 2 sprites. i load it into a spritesheet with:

Code: [Select]
sprite = new SpriteSheet("res/image3.png", 32, 32);
in my rendering procedure i try to print the second sprite onto a quad by doing this:

Code: [Select]
sprite.getSprite(1, 0).bind();

GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0,0);
GL11.glVertex2f(0,0);
GL11.glTexCoord2f(1f,0);
GL11.glVertex2f(32,0);
GL11.glTexCoord2f(1f,1);
GL11.glVertex2f(32,32);
GL11.glTexCoord2f(0,1);
GL11.glVertex2f(0,32);
GL11.glEnd();

instead of showing only the second sprite it shows me both (scaled to 32pixels).


i don't understand why it is not simply binding only the second sprite. thanks for your help.

*

Offline kappa

  • *****
  • 1319
Re: spritesheet binding
« Reply #1 on: February 24, 2012, 17:57:56 »
your resizing the quad, what you need to do is set the correct texture values instead (i.e. amend glTexCoord2f values and not glVertex2f).

Re: spritesheet binding
« Reply #2 on: February 24, 2012, 18:08:34 »
i tried this too. with that i was just able to print the FIRST sprite by doing:

Code: [Select]
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0,0);
GL11.glVertex2f(0,0);
GL11.glTexCoord2f(0.5f,0); //changed 1f to 0.5f
GL11.glVertex2f(32,0);
GL11.glTexCoord2f(0.5f,1); //changed 1f to 0.5f
GL11.glVertex2f(32,32);
GL11.glTexCoord2f(0,1);
GL11.glVertex2f(0,32);
GL11.glEnd();

i don't know how to print the second sprite by changing glTexCoord2f.

Re: spritesheet binding
« Reply #3 on: February 27, 2012, 14:00:25 »
I assume SpriteSheet is from Slick.
From looking at the documentation (http://slick.cokeandcode.com/javadoc/org/newdawn/slick/SpriteSheet.html), it looks like you need to do the following:
Code: [Select]
sprite.startUse();
sprite.renderInUse(x, y, 1, 0);
sprite.endUse();
 
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D