Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How to use a sprite sheet with Slick-util  (Read 447 times)
0 Members and 1 Guest are viewing this topic.
Offline LeTyphoon

Junior Newbie





« Posted 2013-10-23 15:38:29 »

I've just started with game development and I am now making a tile based 2D game. I am using slick-util and lwjgl for my graphics. Right now it loads every texture from it's own png file, but I would like to use a sprite sheet. Could anyone explain how to load a texture from a spritesheet using slick-util?
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #1 - Posted 2013-10-23 16:26:27 »

Using Spritesheets instead of Multiple Images isn't that difficult, just change the Texcoords so that it only draws the parts of the Image you want
Offline LeTyphoon

Junior Newbie





« Reply #2 - Posted 2013-10-23 20:34:06 »

Thank you Seiya02 it works now

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline LeTyphoon

Junior Newbie





« Reply #3 - Posted 2013-10-23 23:18:31 »

EDIT:
I made the tiles larger on the screen, but now there are lines between all tiles.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
public void renderLevel() {
      //terrain is my sprite sheet
     terrain.bind();
     
      //tiles is a 2 dimensional array which contains the tile placements
     for (int i = 0; i < tiles.length; i++) {
         for (int j = 0; j < tiles[1].length; j++) {
           
            //get the index of the tile that gets rendered now (for grass returns 0.0, 2.0 for water)
           float xIndex = level.getTileIndexX(i, j);
            float yIndex = level.getTileIndexY(i, j);

            glPushMatrix();
            {
               glTranslatef(transX, transY, 0);

               glBegin(GL_QUADS);
               {
                 
                  //32.0f is the width and height of a single texture on my sprite sheet, 512.0 is the width and height of my total sprite sheet
                 glTexCoord2d(xIndex * 32.0f / 512.0f, yIndex * 32.0f / 512.0f);
                  glVertex2f(j * tileSize, i * tileSize);

                  glTexCoord2d((xIndex * 32.0f + 32.0f) / 512.0f, yIndex * 32.0f / 512.0f);
                  glVertex2f(tileSize + j * tileSize, i * tileSize);

                  glTexCoord2d((xIndex * 32.0f + 32.0f) / 512.0f, (yIndex * 32.0f + 32.0f) / 512.0f);
                  glVertex2f(tileSize + j * tileSize, i * tileSize + tileSize);

                  glTexCoord2d(xIndex * 32.0f / 512.0f, (yIndex * 32.0f + 32.0f) / 512.0f);
                  glVertex2f(j * tileSize, i * tileSize + tileSize);

               }
               glEnd();
            }
            glPopMatrix();
         }
      }
   }


When i run it the tiles get placed on the right places with the correct textures, but there are thin lines between each adjacent tiles. I've tried to change my sprite sheet, but it didn't fix my problem. Can someone see what I'm doing wrong?
Offline opiop65

JGO Kernel


Medals: 153
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #4 - Posted 2013-10-23 23:26:50 »

Sounds like you need to use some linear filtering:
http://www.opengl.org/sdk/docs/man/xhtml/glTexParameter.xml
And:
http://www.opengl.org/discussion_boards/showthread.php/167808-2D-texture-problem-lines-between-textures
Good luck Smiley

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (39 views)
2014-07-18 06:55:21

Zero Volt (36 views)
2014-07-17 23:47:54

danieldean (29 views)
2014-07-17 23:41:23

MustardPeter (32 views)
2014-07-16 23:30:00

Cero (47 views)
2014-07-16 00:42:17

Riven (48 views)
2014-07-14 18:02:53

OpenGLShaders (38 views)
2014-07-14 16:23:47

Riven (37 views)
2014-07-14 11:51:35

quew8 (33 views)
2014-07-13 13:57:52

SHC (70 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!