Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent duplicating objects when there are multiple tilesets #29

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## [unreleased]

### Features

- Add dedicated marker for Tiled objects (#22) and for objects layer, group layer and images layer
- Regroup tilemaps of the same tile layer using different tilesets under a common parent entity `TiledMapTileLayerForTileset`

### Bugfixes

- Prevent duplicating objects when there are multiple tilesets (#28)

## v0.3.6

### Bugfixes
Expand Down
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()
});
}
16 changes: 16 additions & 0 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,30 @@ pub struct TiledMapLayer {
#[derive(Component)]
pub struct TiledMapTileLayer;

/// Marker component for a Tiled map tile layer for a given tileset.
#[derive(Component)]
pub struct TiledMapTileLayerForTileset;

/// Marker component for a Tiled map object layer.
#[derive(Component)]
pub struct TiledMapObjectLayer;

/// Marker component for a Tiled map group layer.
#[derive(Component)]
pub struct TiledMapGroupLayer;

/// Marker component for a Tiled map image layer.
#[derive(Component)]
pub struct TiledMapImageLayer;

/// Marker component for a Tiled map tile.
#[derive(Component)]
pub struct TiledMapTile;

/// Marker component for a Tiled map object.
#[derive(Component)]
pub struct TiledMapObject;

#[derive(Default, Clone)]
pub enum MapPositioning {
#[default]
Expand Down
Loading