Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Using more than one texture  (Read 893 times)
0 Members and 1 Guest are viewing this topic.
Offline jammas615

Junior Member


Projects: 1



« Posted 2011-12-25 05:27:14 »

I am trying to use more than one texture image when drawing tiles to my game screen.
I have a map file with 1's and 0's which correspond to the 2 textures i have.

I created an array of two slick2d textures, like so: Texture[2] tex; ...And loaded the into tex[0] and tex[1].
When i load the map file to an array and then try passing the texture with the array index being the current index of the map array which passes either 1 or 0 as the texture index.

1  
2  
3  
4  
5  
6  
7  
8  
9  
      
for (int yTile = 0; yTile < 640 / 64; yTile++) {
   for (int xTile = 0; xTile < 768 / 64; xTile++) {
      int i = 0;
      Tile tile = (Tile)tiles.get(i);
      tile.render(tex[map[i]], xTile * Tile.TILE_WIDTH, yTile * Tile.TILE_HEIGHT);
      i++;
   }
}


All i get is one of the tile textures rendered.

Here is the tile class's render method:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
   public void render(Texture bindTex, int xOff, int yOff) {
      bindTex.bind();
      glBegin(GL_QUADS);
         glTexCoord2f(0.0f, 0.0f);
         glVertex2i(xOff, yOff);
         glTexCoord2f(1.0f, 0.0f);
         glVertex2i(xOff + TILE_WIDTH, yOff);
         glTexCoord2f(1.0f, 1.0f);
         glVertex2i(xOff +TILE_WIDTH, yOff + TILE_HEIGHT);
         glTexCoord2f(0.0f, 1.0f);
         glVertex2i(xOff, yOff +TILE_HEIGHT);
      glEnd();
   }


What is happening?

Offline theagentd
« Reply #1 - Posted 2011-12-25 08:43:21 »

You aren't drawing with the second texture. The variable i is always 0, as you never use it when it is 1. >_>

Myomyomyo.
Offline jammas615

Junior Member


Projects: 1



« Reply #2 - Posted 2011-12-25 11:57:24 »

I don't quite get what you mean, how am I not using the second texture?

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

Senior Member


Medals: 7
Exp: 1 year



« Reply #3 - Posted 2011-12-25 12:06:25 »

1  
2  
3  
4  
5  
6  
for (int xTile = 0; xTile < 768 / 64; xTile++) {
      int i = 0;
      Tile tile = (Tile)tiles.get(i);
      tile.render(tex[map[i]], xTile * Tile.TILE_WIDTH, yTile * Tile.TILE_HEIGHT);
      i++;
   }


He's talking about this i = 0; You're establishing an int i = 0; then incrementing it at the end of the loop... then when the loop restarts you recreate it at 0 Cheesy  you need to put the int i = 0 elsewhere, probably at the very beginning of the method (haven't read it all)
Offline jammas615

Junior Member


Projects: 1



« Reply #4 - Posted 2011-12-25 12:17:19 »

Faaaaaark I've been looking at that loop for ages and still didnt see it.
Thanks for your help.

Offline Cero
« Reply #5 - Posted 2011-12-26 14:44:57 »

also, your drawing one quad for every tile
very slow with many tiles

maybe it doesnt matter to you; but if you experience performance issues - just so you know

Offline tw0v

Junior Member


Medals: 1
Projects: 1



« Reply #6 - Posted 2011-12-26 15:00:48 »

rookie error mate

Programming for better games.
Offline Mike

JGO Wizard


Medals: 76
Projects: 1
Exp: 6 years


Java guru wanabee


« Reply #7 - Posted 2011-12-26 15:07:10 »

rookie error mate

Interesting first post...

Mike

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline tw0v

Junior Member


Medals: 1
Projects: 1



« Reply #8 - Posted 2011-12-26 15:11:39 »

i'll be contributing in due time, don't you worry Wink
i'm researching networking atm, then moving onto Java 2D.
I've been messing with 2D side scrollers and pokemon styled games but decided i want to progress further.
haha, i've been reading this forum for a while and forgot to register. my name will be known... hopefully Smiley

Programming for better games.
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.

BurntPizza (25 views)
2014-09-19 03:14:18

Dwinin (39 views)
2014-09-12 09:08:26

Norakomi (69 views)
2014-09-10 13:57:51

TehJavaDev (94 views)
2014-09-10 06:39:09

Tekkerue (48 views)
2014-09-09 02:24:56

mitcheeb (69 views)
2014-09-08 06:06:29

BurntPizza (51 views)
2014-09-07 01:13:42

Longarmx (38 views)
2014-09-07 01:12:14

Longarmx (44 views)
2014-09-07 01:11:22

Longarmx (40 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!