diff --git a/assets/maps/mainmap.tmx b/assets/maps/mainmap.tmx index 73f9c89..62fd9df 100644 --- a/assets/maps/mainmap.tmx +++ b/assets/maps/mainmap.tmx @@ -1,36 +1,23 @@ - + - + - eJylkjsPwjAMhDPykCoeEjDBxkgzARPqBEywla2w9lfkr3OVYulkuSHA8Elt5DvH5wTn3BosDTYgfMHEOCtBEb/34KA4GpotGBjnRfR4gJZ4girW7AwN/3ezrsApam/gQlyNvp3nIubhySOQT2XocuGZ2MdnaiVL8WhA3ZOtoPegM2Vqo16Qflwvmd4Tnry7Vu2Ad+EpY6uHJpWV+LzI55e9neNsfAfr3eR6sbb8UK/f978MwUgx7qlN3W0KZop5Rv83Ub9shA== + eJylkjsPwjAMhLPykCoeEjDBxkgzARPqBEywla2w9lfkp3OVYumwTAgwfFIb+c7xOcE5twRzgxUIXzAyzkpQxO8t2Cn2hmYNesZ5ET1uoCXuoIo1G0PD/92sC3CI2gs4EWejb+c5i3l48gjkUxm6XHgm9vGZWslSPBpQOztbQe9BZ8rURr0g/bheMr0mPHl3rXvdAe/CU8ZWD00qK/F5kM8vezvG2fgO1rvJ9WJt+aFev+9/6YOBYvimNnW3MZgophn9n9wdbaQ= - eJxjYBgFo2AUjALKgRES25BIPQAWUABk - - - - - eJxjYBgFo2AUjIKBAQAEgAAB - - - - - eJxjYBgFo2AUjIKBAQAEgAAB + eJxjYBgFo2AUjALKgTES24hIPQAWrABm - - - @@ -38,5 +25,9 @@ + + + + diff --git a/assets/maps/objects.tsx b/assets/maps/objects.tsx index 715e5e1..6425ee0 100644 --- a/assets/maps/objects.tsx +++ b/assets/maps/objects.tsx @@ -19,21 +19,18 @@ - - - - - - - - - - - + + + + + + + + diff --git a/assets/maps/objects/oak_tree.png b/assets/maps/objects/oak_tree.png index 5dbb903..a88b0fc 100644 Binary files a/assets/maps/objects/oak_tree.png and b/assets/maps/objects/oak_tree.png differ diff --git a/core/src/main/java/io/github/com/quillraven/tiled/TiledAshleySpawner.java b/core/src/main/java/io/github/com/quillraven/tiled/TiledAshleySpawner.java index e10232d..f913175 100644 --- a/core/src/main/java/io/github/com/quillraven/tiled/TiledAshleySpawner.java +++ b/core/src/main/java/io/github/com/quillraven/tiled/TiledAshleySpawner.java @@ -4,6 +4,7 @@ import com.badlogic.ashley.core.Engine; import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.Animation; +import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.glutils.FileTextureData; import com.badlogic.gdx.maps.MapLayer; @@ -24,6 +25,7 @@ import com.badlogic.gdx.physics.box2d.PolygonShape; import com.badlogic.gdx.physics.box2d.World; import com.badlogic.gdx.utils.GdxRuntimeException; import io.github.com.quillraven.GdxGame; +import io.github.com.quillraven.asset.AssetService; import io.github.com.quillraven.asset.AtlasAsset; import io.github.com.quillraven.component.Animation2D; import io.github.com.quillraven.component.Animation2D.AnimationType; @@ -44,12 +46,14 @@ public class TiledAshleySpawner { private final World physicWorld; private final MapObjects tmpMapObjects; private final Vector2 tmpVec2; + private final AssetService assetService; - public TiledAshleySpawner(Engine engine, World physicWorld) { + public TiledAshleySpawner(Engine engine, World physicWorld, AssetService assetService) { this.engine = engine; this.physicWorld = physicWorld; this.tmpMapObjects = new MapObjects(); this.tmpVec2 = new Vector2(); + this.assetService = assetService; } public void loadMapObjects(TiledMap tiledMap) { @@ -159,7 +163,7 @@ public class TiledAshleySpawner { private void spawnEntityOf(TiledMapTileMapObject tileMapObject) { Entity entity = this.engine.createEntity(); TiledMapTile tile = tileMapObject.getTile(); - TextureRegion textureRegion = tile.getTextureRegion(); + TextureRegion textureRegion = getTextureRegion(tile); String classType = tile.getProperties().get("type", "", String.class); float sortOffsetY = tile.getProperties().get("sortOffsetY", 0, Integer.class); sortOffsetY *= GdxGame.UNIT_SCALE; @@ -186,6 +190,24 @@ public class TiledAshleySpawner { this.engine.addEntity(entity); } + private TextureRegion getTextureRegion(TiledMapTile tile) { + String atlasAssetStr = tile.getProperties().get("atlasAsset", "OBJECTS", String.class); + AtlasAsset atlasAsset = AtlasAsset.valueOf(atlasAssetStr); + FileTextureData textureData = (FileTextureData) tile.getTextureRegion().getTexture().getTextureData(); + String atlasKey = textureData.getFileHandle().nameWithoutExtension(); + TextureAtlas textureAtlas = assetService.get(atlasAsset); + TextureAtlas.AtlasRegion region = textureAtlas.findRegion(atlasKey + "/" + atlasKey); + if (region != null) { + return region; + } + + // Region not part of an atlas, or the object has an animation. + // If it has an animation, then its region is updated in the AnimationSystem. + // If it has no region, then we render the region of the Tiled editor to show something, but + // that will add one render call due to texture swapping. + return tile.getTextureRegion(); + } + private void addEntityCameraFollow(TiledMapTileMapObject tileMapObject, Entity entity) { boolean cameraFollow = tileMapObject.getProperties().get("camFollow", false, Boolean.class); if (!cameraFollow) return;