Skip to content
Open
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
5 changes: 2 additions & 3 deletions examples/3d_iso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(helpers::tiled::TiledMapBundle {
tiled_map: map_handle,
render_settings: TilemapRenderSettings {
// Map size is 12x12 so we'll have render chunks that are:
// 12 tiles wide and 1 tile tall.
render_chunk_size: UVec2::new(3, 1),
// Enable y-sort
y_sort: true,
..Default::default()
},
..Default::default()
});
Expand Down
20 changes: 20 additions & 0 deletions src/render/chunk.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::cmp::Ordering;
use std::hash::{Hash, Hasher};

use bevy::platform::collections::HashMap;
Expand Down Expand Up @@ -378,6 +379,25 @@ impl RenderChunk2d {

let mut i = 0;

// y_sort tiles inside chunk
if self.y_sort {
// result=[0,1],[1,1],[0,0],[1,0] Keep entities with max X and min Y rendered last (on top)
self.tiles.sort_by(|a, b| {
match (a, b) {
(Some(a), Some(b)) => {
match b.position.y.partial_cmp(&a.position.y) {
Some(Ordering::Equal) => a.position.x.partial_cmp(&b.position.x).unwrap_or(Ordering::Equal),
Some(ord) => ord,
None => Ordering::Equal,
}
}
(None, Some(_)) => Ordering::Greater,
(Some(_), None) => Ordering::Less,
(None, None) => Ordering::Equal,
}
});
}

// Convert tile into mesh data.
for tile in self.tiles.iter().filter_map(|x| x.as_ref()) {
if !tile.visible {
Expand Down