Skip to content

Commit

Permalink
feat: add an example to reproduce #28
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-bon committed Aug 18, 2024
1 parent 9429da0 commit 476e52a
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,6 @@ required-features = ["user_properties", "avian"]

[[example]]
name = "isometric_map"

[[example]]
name = "multiple_tilesets"
25 changes: 25 additions & 0 deletions assets/Tileset2.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.10" tiledversion="1.10.2" name="Tileset2" tilewidth="32" tileheight="32" tilecount="7" columns="0">
<grid orientation="orthogonal" width="1" height="1"/>
<tile id="0">
<image width="32" height="32" source="tiles/tile0.png"/>
</tile>
<tile id="1">
<image width="32" height="32" source="tiles/tile1.png"/>
</tile>
<tile id="2">
<image width="32" height="32" source="tiles/tile2.png"/>
</tile>
<tile id="3">
<image width="32" height="32" source="tiles/tile3.png"/>
</tile>
<tile id="4">
<image width="32" height="32" source="tiles/tile4.png"/>
</tile>
<tile id="5">
<image width="32" height="32" source="tiles/tile5.png"/>
</tile>
<tile id="6">
<image width="32" height="32" source="tiles/tile6.png"/>
</tile>
</tileset>
24 changes: 24 additions & 0 deletions assets/multiple_tilesets.tmx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="10" height="10" tilewidth="32" tileheight="32" infinite="0" nextlayerid="3" nextobjectid="3">
<tileset firstgid="1" source="Tileset1.tsx"/>
<tileset firstgid="8" source="Tileset2.tsx"/>
<layer id="1" name="Tile Layer 1" width="10" height="10">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,1,0,0,0,0,0,0,0,0,
0,1,0,0,0,0,0,0,0,0,
0,1,0,10,10,10,10,0,0,0,
0,1,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,7,0,0,
0,0,0,0,0,0,0,7,0,0,
0,0,12,12,12,12,0,7,0,0,
0,0,0,0,0,0,0,0,0,0
</data>
</layer>
<objectgroup id="2" name="Object Layer 1">
<object id="1" name="My object" x="169.544" y="211.836">
<point/>
</object>
</objectgroup>
</map>
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ In most of the examples, you can use the following action keys:
| `infinite_avian` | `avian` | This example shows an infinite orthogonal map with an external tileset and Avian2D physics. |
| `controller_avian` | `avian` | This example shows a simple player-controlled object using Avian2D physics. You can move the object using arrow keys. |
| `user_properties_avian` | `user_properties`, `avian` | This example shows how to map custom tiles / objects properties from Tiled to Bevy Components and manually spawn Avian colliders from them. |
| `multiple_tilesets` | None | This example shows a finite orthogonal map with multiple external tilesets. |
30 changes: 30 additions & 0 deletions examples/multiple_tilesets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//! This example shows a finite orthogonal map with multiple external tilesets.
use bevy::prelude::*;
use bevy_ecs_tiled::prelude::*;
use bevy_ecs_tilemap::prelude::*;

mod helper;

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(TilemapPlugin)
.add_plugins(TiledMapPlugin)
.add_plugins(helper::HelperPlugin)
.add_systems(Startup, startup)
.run();
}

fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());

// For simplicity sake, we use two tilesets which actually use the same images
// However, we can verify with the inspector that the map actually use tiles
// from both tilesets
let map_handle: Handle<TiledMap> = asset_server.load("multiple_tilesets.tmx");
commands.spawn(TiledMapBundle {
tiled_map: map_handle,
..Default::default()
});
}

0 comments on commit 476e52a

Please sign in to comment.