Skip to content

Commit

Permalink
Fixed 3d iso example..
Browse files Browse the repository at this point in the history
  • Loading branch information
StarArawn committed Mar 25, 2023
1 parent 4f0a21b commit 0970953
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 22 deletions.
28 changes: 14 additions & 14 deletions assets/iso_map.tmx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.4" tiledversion="1.4.3" orientation="isometric" renderorder="right-down" width="12" height="12" tilewidth="64" tileheight="32" infinite="0" nextlayerid="6" nextobjectid="1">
<tileset firstgid="1" name="isometric-sheet" tilewidth="64" tileheight="64" tilecount="9" columns="6">
<map version="1.9" tiledversion="1.9.2" orientation="isometric" renderorder="right-down" width="12" height="12" tilewidth="64" tileheight="32" infinite="0" nextlayerid="6" nextobjectid="1">
<tileset firstgid="1" name="isometric-sheet" tilewidth="64" tileheight="64" tilecount="6" columns="6">
<image source="isometric-sheet.png" trans="ff00ff" width="384" height="64"/>
</tileset>
<layer id="1" name="0" width="12" height="12">
Expand All @@ -24,12 +24,12 @@
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,5,5,5,5,5,5,0,0,0,
0,0,0,5,0,0,0,0,0,0,0,0,
0,0,0,5,0,0,0,0,0,0,0,0,
0,0,0,5,0,0,0,0,0,0,0,0,
0,0,0,5,0,0,0,0,0,0,0,0,
0,0,0,5,0,0,0,0,0,0,0,0,
0,0,0,6,6,6,6,6,6,0,0,0,
0,0,0,6,0,0,0,0,0,0,0,0,
0,0,0,6,0,0,0,0,0,0,0,0,
0,0,0,6,0,0,0,0,0,0,0,0,
0,0,0,6,0,0,0,0,0,0,0,0,
0,0,0,6,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0
Expand All @@ -39,12 +39,12 @@
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,5,5,5,5,5,5,0,0,0,0,
0,0,5,5,5,5,5,5,0,0,0,0,
0,0,5,5,5,5,5,5,0,0,0,0,
0,0,5,5,5,5,5,5,0,0,0,0,
0,0,5,5,5,5,5,0,0,0,0,0,
0,0,5,5,5,5,0,0,0,0,0,0,
0,0,6,6,6,6,6,6,0,0,0,0,
0,0,6,6,6,6,6,6,0,0,0,0,
0,0,6,6,6,6,6,6,0,0,0,0,
0,0,6,6,6,6,6,6,0,0,0,0,
0,0,6,6,6,6,6,0,0,0,0,0,
0,0,6,6,6,6,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
Expand Down
20 changes: 20 additions & 0 deletions assets/iso_map2.tmx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.9" tiledversion="1.9.2" orientation="isometric" renderorder="right-down" width="3" height="3" tilewidth="64" tileheight="32" infinite="0" nextlayerid="6" nextobjectid="1">
<tileset firstgid="1" name="isometric-sheet" tilewidth="64" tileheight="64" tilecount="6" columns="6">
<image source="isometric-sheet.png" trans="ff00ff" width="384" height="64"/>
</tileset>
<layer id="1" name="0" width="3" height="3">
<data encoding="csv">
1,1,1,
1,4,4,
1,4,4
</data>
</layer>
<layer id="4" name="1" width="3" height="3" offsetx="0" offsety="-32">
<data encoding="csv">
0,0,0,
0,6,6,
0,6,6
</data>
</layer>
</map>
44 changes: 44 additions & 0 deletions examples/3d_iso.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use bevy::prelude::*;
use bevy_ecs_tilemap::prelude::*;

mod helpers;

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

let map_handle: Handle<helpers::tiled::TiledMap> = asset_server.load("iso_map.tmx");

commands.spawn(helpers::tiled::TiledMapBundle {
tiled_map: map_handle,
..Default::default()
});
}

fn main() {
App::new()
.insert_resource(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),
})
.add_plugins(
DefaultPlugins
.set(WindowPlugin {
primary_window: Some(Window {
title: String::from("Color Example"),
..Default::default()
}),
..default()
})
.set(ImagePlugin::default_nearest())
.set(AssetPlugin {
watch_for_changes: true,
..default()
}),
)
.add_plugin(TilemapPlugin)
.add_plugin(helpers::tiled::TiledMapPlugin)
.add_startup_system(startup)
.add_system(helpers::camera::movement)
.run();
}
10 changes: 10 additions & 0 deletions examples/colors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy::prelude::*;
use bevy_ecs_tilemap::prelude::*;
use rand::{thread_rng, Rng};

mod helpers;

Expand Down Expand Up @@ -90,6 +91,14 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
});
}

fn change_color(mut query: Query<&mut TileColor>) {
let mut random = thread_rng();

for mut color in query.iter_mut() {
*color = TileColor(Color::rgb(random.gen(), random.gen(), random.gen()));
}
}

fn main() {
App::new()
.add_plugins(
Expand All @@ -106,5 +115,6 @@ fn main() {
.add_plugin(TilemapPlugin)
.add_startup_system(startup)
.add_system(helpers::camera::movement)
.add_system(change_color)
.run();
}
8 changes: 3 additions & 5 deletions examples/helpers/tiled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,9 @@ pub fn process_loaded_maps(

for x in 0..map_size.x {
for y in 0..map_size.y {
let mut mapped_y = y;
if tiled_map.map.orientation == tiled::Orientation::Orthogonal {
mapped_y = (tiled_map.map.height - 1) - y;
}

// Transform TMX coords into bevy coords.
let mapped_y = tiled_map.map.height - 1 - y;

let mapped_x = x as i32;
let mapped_y = mapped_y as i32;

Expand Down
4 changes: 2 additions & 2 deletions src/render/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ pub struct RenderChunk2d {
/// [`TilemapType`] of the map this chunk belongs to.
map_type: TilemapType,
/// The grid size of the map this chunk belongs to.
grid_size: TilemapGridSize,
pub grid_size: TilemapGridSize,
/// The tile size of the map this chunk belongs to.
tile_size: TilemapTileSize,
pub tile_size: TilemapTileSize,
/// The [`Aabb`] of this chunk, based on the map type, grid size, and tile size. It is not
/// transformed by the `global_transform` or [`local_transform`]
aabb: Aabb,
Expand Down
3 changes: 2 additions & 1 deletion src/render/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,12 @@ pub fn queue_meshes(
};

let pipeline_id = pipelines.specialize(&pipeline_cache, &tilemap_pipeline, key);
let z = transform.translation.z + (1.0 - (transform.translation.y / (chunk.map_size.y as f32 * chunk.tile_size.y)));
transparent_phase.add(Transparent2d {
entity,
draw_function: draw_tilemap,
pipeline: pipeline_id,
sort_key: FloatOrd(transform.translation.z),
sort_key: FloatOrd(z),
batch_range: None,
});
}
Expand Down

0 comments on commit 0970953

Please sign in to comment.