TMXLoader v0.3 released

moveToTile(tilePos.x + 0.5, tilePos.y + 0.5) add (0.5, 0.5) if you want to look at tile center

1 Like

moveToTile will move that tile to screen center, but getCursorTileCoordinate() may be not the center tile.

maybe there should be a getCenterTileCoordinate() or something like dontMoveTile( getCursorTileCoordinate() )

I think this may help

	public Vector2f getCameraPixelCoordinate() {
		if (inputManager == null) {
			throw new IllegalStateException(
					"inputManager is null. Please initialize TiledMapAppState first.");
		Vector2f center = new Vector2f(screenDimension.x * 0.5f, screenDimension.y * 0.5f);
		center = center.subtract(mapTranslation.x, mapTranslation.z).divideLocal(mapScale);
		return getMapRenderer().screenToPixelCoords(center.x, center.y);

	public void moveToPixel(float x, float y) {
		Vector2f pixelPos = mapRenderer.pixelToScreenCoords(x, y).multLocal(getMapScale());
		Vector2f camPos = new Vector2f(cam.getLocation().x, screenDimension.y - cam.getLocation().y);
		camPos.subtract(pixelPos, pixelPos);
		mapTranslation.set(pixelPos.x, 0, pixelPos.y);

	public void zoomCamera(float value) {
		// store the current position
		Vector2f pixel = getCameraPixelCoordinate();

		viewColumns += zoomSpeed * value;

		// at less see 1 tile on screen
		if (viewColumns < 1f) {
			viewColumns = 1f;


		// restore the position
		moveToPixel(pixel.x, pixel.y);
1 Like

yeah that working perfect thanks!

why setBackground not working? Im doing smth wrong?

It’s a bug. As the TiledMapAppState is not initialized yet, viewPort is null here, so backgroundColor is not set.

It’s easy to fix, just add 2 lines of code after initialized.

if ( != null) {

I never thought anyone would use this TiledMap class by code.
I will push a fix to the repo.


I’m trying to look into the latest tiled 1.10.2 to figure out what’s new. Maybe I can add infinite world, WangSet to TMXLoader.


Hello, can u help me please. I cant understand how to add new ObjectNode into game, I’m trying to create it but cant understand how to load texture for it.

Also im facing the hit box bug when im trying to click on objects that already exist on map that i created with Tiled. For some reason hit-box moved down

p.s problem with object creation solved, still cant understand why visual and hit box of object are moved


Would you please provide any sample code to reproduce that hit-box bug?

1 Like

im creating object via tiled and then just trying to get it by mouse click, i think i can solve problem just adding an offset to the coordinates.

i also wanted to ask is it bug that i can see this lines between tiles?

I will try to find out what happened, when I’m not so busy with my work.

For the line, I suggest to stretch the tile around 1px, make its color the same as the tile background color.

1 Like

I also wanted to ask about Images objects in Tiled is it possible to do ? Because im adding Image via Tiled but its not working in Parallax also working?

ImageObject is support, but I’m not sure what is the ‘Parallax’ feature. Tiled is updated to 1.10.2 now, but this lib is below 1.3.0. The new features may not work.

1 Like

I got problem with ImageLayer its not loading image, but objects still exist in ImageLayer, i need just to specify image path in Tiled?

It doesn’t matter how you specify the path in Tiled, It’s how the files organized in jme3.
In jme3 project I suppose that all the files needed are in the same folder.

1 Like

For some reason ImageLayer does not show image what can be the problem?

I checked ImageLayer and his Visual is null is it ok?

The visual object is instanced when rendering the map, and the imageLayer must be visible.

Has your ImageLayer set visible = 1 ?

see MapRenderer line 312

    protected Spatial render(ImageLayer layer) {
        Mesh mesh = ObjectMesh.makeRectangle(mapSize.x, mapSize.y);
        Geometry geom = new Geometry(layer.getName(), mesh);


        return layer.getVisual();

1 Like

Idk smth going wrong everthing is rendered properly but i cant see the image, would you answer i have some other options on how I can put the image into background that will never move

It’s a bug that image layer not shown, I’ll fix it soon.

It’s now support ImageLayer, GroupLayer and Tinting Color. the Parallax Scrolling feature need more work to do.


Finally I figure out why there are those lines.

The actual tile size is less than the tile size read from “*.tmx” file.

For example, in the Hexagonal demo 01.tmx, tilewidth = 65, tileheight=65.


<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="hexagonal" renderorder="right-down" width="10" height="10" 
 tilewidth="65" tileheight="65" hexsidelength="31" staggeraxis="y" staggerindex="even" backgroundcolor="#90a1a2" nextobjectid="2">
 <tileset firstgid="1" name="Hex1_65x65_65x230" tilewidth="65" tileheight="230">
  <image source="01_65x65_65x230.png" width="1300" height="690"/>

This is how it looks in tiled mapeditor, render tile size in 64x65:

This is how it looks with tmxloader, render tile size in 65x65:

As the tile is 1 pixel greater than it should be, those lines come.

The tile size should be re-calculate in Hexagonal map renderer.

        int sideLengthX = sideLengthY = 0;
        if (staggerX) {
            sideLengthX = map.getHexSideLength();
        } else {
            sideLengthY = map.getHexSideLength();

        int sideOffsetX = (map.getTileWidth() - sideLengthX) / 2;
        int sideOffsetY = (map.getTileHeight() - sideLengthY) / 2;

        int columnWidth = sideOffsetX + sideLengthX;
        int rowHeight = sideOffsetY + sideLengthY;

        // re-calculate the tile size
        tileWidth = columnWidth + sideOffsetX;
        tileHeight = rowHeight + sideOffsetY;

The final result:

Still working on that lines between tiles.

The texture clamp to edge wrap mode failed with texture atlas, the edge uv-coordinate have to be clamped in fragment shader.

vec2 getTileUVClamped(vec2 tilePos, vec2 tileSize, vec2 imageSize) {
    vec2 pixel = v_TexCoord * tileSize + tilePos;
    vec2 min = vec2(tilePos + 0.5);
    vec2 max = vec2(tilePos + tileSize - 0.5);
    vec2 uv = clamp(pixel, min, max) / imageSize;
    uv.y = 1.0 - uv.y;
    return uv;