Slick Forums

Discuss the Slick 2D Library
It is currently Fri May 24, 2013 3:55 pm

All times are UTC




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: BUG: TiledMap
PostPosted: Mon Jul 09, 2007 10:15 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
Hi,

I have a map I created in Tiled. It has tile textures of size 32x64. Everything works fine in Tiled editor, but when I load up the map in Slick it goes all havoc.

Only the first row of all layers (besides the terrain) is displayed.

It has something to do with that 32x64 tile graphics.

Here is a link to the stuff needed for debugging this, most likely a problem with the TiledMap loader.

http://www.private.is/arni/map.zip


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 09, 2007 10:35 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
Quote:
[22:31:26] <kevglass> the way it's coded at the moment it assumes the lines can be drawn in turn rather than the layers - for using with rpgmaker style maps
[22:32:11] <kevglass> until there's a fix made available you could call render for each layer in turn, that should make it work
[22:32:39] <kevglass> map.render(10, 10, 0,0,25,25,0,false);
[22:32:39] <kevglass> map.render(10, 10, 0,0,25,25,1,false);


The above solution works!

Added for Tommy :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 10, 2007 7:10 am 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
appel wrote:
Added for Tommy :)

Thanks appel :wink:
But I'm doing that already in my game (look here for the old beta version).
Final release really soon!

Rendering each layer in turn is required anyway if you keep in mind that you need to render your game objects (player, monster, whatever) too.
So the code looks something like
Code:
   // warning: this is pseudo code, not Java...
   render ground layer;
   render ground objects; // stuff like drop items where player can stand above
   render object layer; // the layer with trees and walls and such
   render objects; // player, monster, animated thingies and such
   render top layer; // tree tops, roofs, ceilings, everything that can cover stuff below
   render top objects; // flying things for example


And finally you'll need to add the particle effects somewhere in between or even those separated on several layers :roll:

And you might even need to do that row by row from top to bottom to achieve something like a Z ordering...

Cheers,
Tommy

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 10, 2007 9:18 am 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
Yup, I was going to do it like that, but wanted to use the map.render() all to see the map load in, just the way I work :) make it work generically first, then start to specialize.

There was still some bug with rendering each layer independently, I'll post it tonight as I'm at work currently and don't have the project on my work pc.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 10, 2007 7:04 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
Ok, you should be able to use the same map.zip file as I posted above to reproduce this.

The code I use is to render:

Code:
      map.render(0, 0, round(tileX), round(tileY), container.getWidth()/map.getTileWidth()+1, container.getHeight()/map.getTileHeight()+1,0,false);
      map.render(0, 0, round(tileX), round(tileY), container.getWidth()/map.getTileWidth()+1, container.getHeight()/map.getTileHeight()+1,1,false);


The results:
You can see how it looks like in Tiled, and how it is rendered.

Image


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 10, 2007 7:32 pm 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
Hi appel,
can you post the code of your map loader/renderer so that we can reproduce your problem easily?
A simple test class would do.

I think I found a bug in class TileSet (also in TiledMap.java). There seems to be a copy/paste error in method getTileY() which could be the cause of your problem.

Original code is:
Code:
      public int getTileY(int id) {   
         return id / tilesAcross;
      }


The correct version should be (I think):
Code:
      public int getTileY(int id) {   
         return id / tilesDown;
      }


If you have the source code of Slick you could give that a try by changing the method. Or if you post a simple testcase using your map I'll give it a try and if that's the proper one I'd fix it.

Cheers,
Tommy

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 10, 2007 7:47 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
Code:
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.tiled.TiledMap;

public class Game extends BasicGame {

   private TiledMap map;
   
   public Game(String title) {
      super(title);
   }

   @Override
   public void init(GameContainer container) throws SlickException {
      map = new TiledMap("resources/maps/map01b.tmx","resources/maps");

   }

   @Override
   public void update(GameContainer container, int delta) throws SlickException {
   }

   public void render(GameContainer container, Graphics g) throws SlickException {
      map.render(0, 0, 0, 0, container.getWidth()/map.getTileWidth()+1, container.getHeight()/map.getTileHeight()+1,0,false);
      map.render(0, 0, 0, 0, container.getWidth()/map.getTileWidth()+1, container.getHeight()/map.getTileHeight()+1,1,false);

   }
   
   public static void main(String[] argv) {
      try {
         AppGameContainer container = new AppGameContainer(new Game("Game"));
         container.setDisplayMode(640,480,false);
         container.start();
      } catch (SlickException e) {
         e.printStackTrace();
      }
   }

}


just change path to the map files.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 10, 2007 8:12 pm 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
As usual my first assumption was wrong :lol:

I'll have a look - I've setup a working testcase now.

Later,
Tommy

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 10, 2007 9:14 pm 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
A little progress:
Image

Now the 32x64 tiles are all just 32 pixels off in the y direction.

There is one bug in the rendering of the layers.
The tilewidth and tileheight of the tileset are used but the map tilewidth and tileheight should be used instead.

I'm too tired right now to continue, maybe Kev or some other dev finds a minute...

TiledMap.java, inner class Layer, public void render() method:
Code:
set.tiles.renderInUse(x+(tx*set.tileWidth), y+(ty*set.tileHeight), sheetX, sheetY);

should be
Code:
set.tiles.renderInUse(x+(tx*mapTileWidth), y+(ty*mapTileHeight), sheetX, sheetY);


render() needs to get mapTileWidth and mapTileHeight as two additional parameters. It's only called in two places in TiledMap.java, easy to add.

But currently I don't know why those 32x64 tiles are all 32 pixels off.
Idea: could it be the case that Tiled uses lower left corner for tile coordinates instead of upper left?

G'night,
Tommy

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 11:14 am 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
Hey, thanks Tommy :)

However, I tried your solution, I simply hardcoded in the mapTileWidth and mapTileHeight values to see what happened. The results were a total mess.

Code:
set.tiles.renderInUse(x+(tx*mapTileWidth), y+(ty*mapTileHeight), sheetX, sheetY);


mapTileWidth should be the number of tiles across, and mapTileHeight the number of tiles down? So a 640x1024 map (in pixels) with tile size 32x32, would be of size mapTileWidth=20 and mapTileHeight=32 ? (That's what I tried btw.)

Sorry I'm at work and don't have any more code/screenies :( I'll post tonight.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 1:04 pm 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
No, no.
MapTileWidth and MapTileHeight means the tile width and tile height that is set for your map (in your map it's 32x32). So they would both be 32.
You can look at the values by opening your map file (the tmx) with a text editor.

The error in the layer.render() is that it's looping based on the map's tile size (32x32) but calculating using the tileset's tile sizes (32x64).
T
hat's what I fixed by adding two more parameters to Layer.render(). It's called from two places in TiledMap.java, both times from the TiledMap class so the map's tile sizes are two instance variables which I just needed to pass as the two additional parameters.

Now we just need to find out where the offset of 32 pixels (ring, ring: tileset.tileheight - tilemap.tileheight = 64-32 = 32...) comes from.

All the stuff currently seems to work fine if the map and all tilesets use the same tilesize (32x32 for example).

So your issue does help to improve the TiledMap support - so where's the bug now? :wink:

Cheers,
Tommy

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 15, 2007 8:07 pm 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
Still looking at this.
Just needed to get my SpiderTrap update out :wink:

Tommy

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 9:09 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Tommy, any progress on this one - I finally have some time, so I can take a look if needed.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 17, 2007 9:42 am 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
Help would be appreciated - I would look at it tonight.
Maybe we can discuss it. Should I commit the minimal changes I did?

Cheers,
Tommy

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 17, 2007 10:13 am 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Commit away, I just want to get it resolved so appel can get on with what looks like it'll be my sort of game ;)

Kev


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group