fix prop graphic's region to use the correct atlas region
This commit is contained in:
@@ -1,36 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="18" height="16" tilewidth="16" tileheight="16" infinite="0" nextlayerid="7" nextobjectid="11">
|
||||
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="18" height="16" tilewidth="16" tileheight="16" infinite="0" nextlayerid="7" nextobjectid="15">
|
||||
<properties>
|
||||
<property name="music" value="TOWN"/>
|
||||
</properties>
|
||||
<tileset firstgid="1" source="objects.tsx"/>
|
||||
<tileset firstgid="6" source="tileset.tsx"/>
|
||||
<tileset firstgid="7" source="tileset.tsx"/>
|
||||
<layer id="1" name="ground" width="18" height="16">
|
||||
<data encoding="base64" compression="zlib">
|
||||
eJylkjsPwjAMhDPykCoeEjDBxkgzARPqBEywla2w9lfkr3OVYulkuSHA8Elt5DvH5wTn3BosDTYgfMHEOCtBEb/34KA4GpotGBjnRfR4gJZ4girW7AwN/3ezrsApam/gQlyNvp3nIubhySOQT2XocuGZ2MdnaiVL8WhA3ZOtoPegM2Vqo16Qflwvmd4Tnry7Vu2Ad+EpY6uHJpWV+LzI55e9neNsfAfr3eR6sbb8UK/f978MwUgx7qlN3W0KZop5Rv83Ub9shA==
|
||||
eJylkjsPwjAMhLPykCoeEjDBxkgzARPqBEywla2w9lfkp3OVYumwTAgwfFIb+c7xOcE5twRzgxUIXzAyzkpQxO8t2Cn2hmYNesZ5ET1uoCXuoIo1G0PD/92sC3CI2gs4EWejb+c5i3l48gjkUxm6XHgm9vGZWslSPBpQOztbQe9BZ8rURr0g/bheMr0mPHl3rXvdAe/CU8ZWD00qK/F5kM8vezvG2fgO1rvJ9WJt+aFev+9/6YOBYvimNnW3MZgophn9n9wdbaQ=
|
||||
</data>
|
||||
</layer>
|
||||
<layer id="3" name="water" width="18" height="16">
|
||||
<data encoding="base64" compression="zlib">
|
||||
eJxjYBgFo2AUjALKgRES25BIPQAWUABk
|
||||
</data>
|
||||
</layer>
|
||||
<layer id="4" name="water2" width="18" height="16">
|
||||
<data encoding="base64" compression="zlib">
|
||||
eJxjYBgFo2AUjIKBAQAEgAAB
|
||||
</data>
|
||||
</layer>
|
||||
<layer id="2" name="props" width="18" height="16">
|
||||
<data encoding="base64" compression="zlib">
|
||||
eJxjYBgFo2AUjIKBAQAEgAAB
|
||||
eJxjYBgFo2AUjALKgTES24hIPQAWrABm
|
||||
</data>
|
||||
</layer>
|
||||
<objectgroup id="6" name="trigger"/>
|
||||
<objectgroup id="5" name="objects">
|
||||
<object id="5" gid="3" x="197" y="118" width="80" height="112"/>
|
||||
<object id="6" gid="4" x="58" y="101" width="64" height="80"/>
|
||||
<object id="7" gid="4" x="43" y="215" width="64" height="80"/>
|
||||
<object id="8" gid="4" x="199" y="216" width="64" height="80"/>
|
||||
<object id="9" gid="5" x="32" y="32" width="16" height="16"/>
|
||||
<object id="10" gid="2" x="25" y="214" width="32" height="32">
|
||||
<properties>
|
||||
@@ -38,5 +25,9 @@
|
||||
<property name="controller" type="bool" value="true"/>
|
||||
</properties>
|
||||
</object>
|
||||
<object id="11" gid="6" x="44" y="200" width="41" height="63"/>
|
||||
<object id="12" gid="6" x="137" y="206" width="41" height="63"/>
|
||||
<object id="13" gid="6" x="72" y="93" width="41" height="63"/>
|
||||
<object id="14" gid="6" x="176" y="123" width="41" height="63"/>
|
||||
</objectgroup>
|
||||
</map>
|
||||
|
||||
@@ -19,21 +19,18 @@
|
||||
<object id="1" x="7" y="82" width="67" height="26"/>
|
||||
</objectgroup>
|
||||
</tile>
|
||||
<tile id="3" type="Prop">
|
||||
<properties>
|
||||
<property name="sortOffsetY" type="int" value="8"/>
|
||||
</properties>
|
||||
<image source="objects/oak_tree.png" width="64" height="80"/>
|
||||
<objectgroup draworder="index" id="2">
|
||||
<object id="2" x="24" y="63">
|
||||
<polygon points="0,0 6,1 11,1 16,-1 16,-2 13,-6 13,-12 3,-12 3,-6 2,-5 1,-3"/>
|
||||
</object>
|
||||
</objectgroup>
|
||||
</tile>
|
||||
<tile id="4" type="Prop">
|
||||
<image source="objects/chest.png" width="16" height="16"/>
|
||||
<objectgroup draworder="index" id="2">
|
||||
<object id="1" x="0" y="4" width="16" height="10"/>
|
||||
</objectgroup>
|
||||
</tile>
|
||||
<tile id="5" type="Prop">
|
||||
<image source="objects/oak_tree.png" width="41" height="63"/>
|
||||
<objectgroup draworder="index" id="2">
|
||||
<object id="1" x="13" y="54">
|
||||
<polygon points="0,0 6,1 11,1 16,-1 16,-2 14,-5 13,-13 3,-13 3,-6 2,-5 1,-3 0,-1"/>
|
||||
</object>
|
||||
</objectgroup>
|
||||
</tile>
|
||||
</tileset>
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 5.3 KiB |
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user