[Slick2d] Convert TiledMap to use Float instead of Int.

In my dire need to make TiledMaps render smoother, I figured out the steps needed to modify Slick2D’s TiledMap class (and the classes effected by it) to accept floats instead of ints, that way you can move the map via float*delta, instead of just straight ints. This will allow your maps to move much smoother around the map.

This process actually ended up being a lot more simple than I had originally thought but I figured I should still share the process anyway, it’s only 6 edits in 3 files. I removed a few edits that didn’t need to be done, to keep this as minimally invasive as possible to Slick2d.

(This is done with Slick2d build #237, the exact lines may differ in your copy)

org.newdawn.slick.tiled.TiledMap.class
Line: 417
Change:

	public void render(int x, int y, int sx, int sy, int width, int height,

To:

	public void render(float x, float y, int sx, int sy, int width, int height,

Line: 502

	protected void renderIsometricMap(int x, int y, int sx, int sy, int width,

To:

	protected void renderIsometricMap(float x, float y, int sx, int sy, int width,

Lines: 515, 516

	int initialLineX = x;
	int initialLineY = y;

To:

	float initialLineX = x;
	float initialLineY = y;

Line: 524

	int currentLineX = initialLineX;

To:

	float currentLineX = initialLineX;

org.newdawn.slick.tiled.Layer
Line 198

	public void render(int x, int y, int sx, int sy, int width, int ty,

To:

	public void render(float x, float y, int sx, int sy, int width, int ty,

org.newdawn.slick.SpriteSheet
Line 267

	public void renderInUse(int x,int y,int sx,int sy) {

To:

	public void renderInUse(float x,float y,int sx,int sy) {

Dumb question… How do I make edits in eclipse? Every time I try & open the TiledMap.class it shows a “source not found” error.

You have to grab the slick2d source code (should be supplied in the slick2d download), and grab the .java files you want to edit. Then place them in your Workspace in the same folders.

  1. Right click on your \src\ folder in your program
  2. Click “New Package”
  3. Name the new package org.newdawn.slick
    3b. Repeat, make another package called org.newdawn.slick.tiled (Or make a \tiled\ folder in org.newdawn.slick)
  4. Go into the Slick2d zip file you downloaded (Not just the jar, the file with everything in it, sourcecode, javadocs, etc)
  5. Navigate to \src\org\newdawn\slick, drag and drop SpriteSheet.java into org.newdawn.slick
  6. Navigate to \src\org\newdawn\slick\tiled and drag and drop Layer.java and TiledMap.java into your org.newdawn.slick.tiled folder

The alternative method would be to just drag+drop the entire Slick2d source code into org.newdawn.slick and delete the reference library completely inside your project, but then you’d be recompiling the entire slick2d source code every time you export the game, really wont hurt anything but why bother? One benefit to this is once your game is “complete” you could selectively remove parts of Slick2d you don’t use in your game. But really, that’d be silly. Slick isnt that big. :smiley: