Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (769)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
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  
  Weird tilemap rendering not working  (Read 1501 times)
0 Members and 1 Guest are viewing this topic.
Offline Ging3rtoby
« Posted 2014-09-04 10:55:22 »

The game I am currently working on has a very weird rendering error. It loads text from a file and sets a specific tile to a certain text (If you get what I mean). It has this very weird rendering error though. 



The textures move a couple of pixels to the right. This is what my spritesheet looks like.



And the some snippets of the code.

Loading the map:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
   public void LoadWallsMap(String filename, int tileSize) {
      this.tileSize = tileSize;

      try {
         @SuppressWarnings("resource")
         BufferedReader br = new BufferedReader(new FileReader("res/maps/" + filename));

         mapWidth = Integer.parseInt(br.readLine());
         mapHeight = Integer.parseInt(br.readLine());

         mapWalls = new int[mapHeight][mapWidth];

         for (int row = 0; row < mapHeight; row++) {
            String line = br.readLine();
            String[] tokens = line.split(" ");
            for (int column = 0; column < mapWidth; column++) {
               mapWalls[row][column] = Integer.parseInt(tokens[column]);
            }
         }
      } catch (Exception e) {
         e.printStackTrace();
      }
   }


And rendering the map:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
   public void renderWallsMap(Graphics g) {
      for (int row = 0; row < mapHeight; row++) {
         for (int column = 0; column < mapWidth; column++) {
            int x = mapWalls[row][column];
            if(x == 1) renderTile(Tile.wallTop, x, y, column, row, g);
            if(x == 2) renderTile(Tile.wallTopMiddle, x, y, column, row, g);
            if(x == 3) renderTile(Tile.wallSide, x, y, column, row, g);
            if(x == 4) renderTile(Tile.wallBottom, x, y, column, row, g);
            if(x == 5) renderTile(Tile.wallBottomMiddle, x, y, column, row, g);
         }
      }
   }


1  
2  
3  
   public void renderTile(Tile tile, int x, int y, int column, int row, Graphics g) {
      tile.render(x + column * tileSize, y + row * tileSize, g);
   }


Any help would be much appreciated.

Thanks Toby
Offline LiquidNitrogen
« Reply #1 - Posted 2014-09-04 12:50:08 »

Can you give more details on what the problem is? The image doesn't show enough to understand what to look for.
Offline Ging3rtoby
« Reply #2 - Posted 2014-09-04 15:06:17 »

Okay, sorry. Look at the first image, can you see there are black walls. The middle ones are slightly to the right, when I want them to just be straight. I dont understand why it is happening. They should be drawn probably in the spritesheet (image below)

Hope that helps
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline LiquidNitrogen
« Reply #3 - Posted 2014-09-05 02:19:46 »

ah right, i didnt realize that the image was a link to a larger image.

1  
    tile.render(x + column * tileSize, y + row * tileSize, g);


..this looks a little strange. x appears to be a tile type which you are getting out of your map, but then you are adding it onto the drawing position also, so i imagine that could be what is shifting them. It looks like you should either change the renderTile() to not use the x and y, or change:

1  
2  
3  
4  
5  
if(x == 1) renderTile(Tile.wallTop, x, y, column, row, g);

..to..

if(x == 1) renderTile(Tile.wallTop, 0, 0, column, row, g);


Offline Ging3rtoby
« Reply #4 - Posted 2014-09-05 16:05:03 »

Oh im so stupid, I just needed to change a variable name and now it works fine. Thanks alot.

Toby
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1669 views)
2018-06-10 19:43:48

EgonOlsen (1706 views)
2018-06-10 19:43:44

EgonOlsen (1158 views)
2018-06-10 19:43:20

DesertCoockie (1585 views)
2018-05-13 18:23:11

nelsongames (1185 views)
2018-04-24 18:15:36

nelsongames (1709 views)
2018-04-24 18:14:32

ivj94 (2533 views)
2018-03-24 14:47:39

ivj94 (1758 views)
2018-03-24 14:46:31

ivj94 (2835 views)
2018-03-24 14:43:53

Solater (971 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!