Skip to content

Commit

Permalink
Fixed issues with chunk positions for 3D iso.
Browse files Browse the repository at this point in the history
  • Loading branch information
StarArawn committed Feb 4, 2022
1 parent 44c026c commit af750d5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 32 deletions.
35 changes: 4 additions & 31 deletions examples/improved_iso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query
// Important for ISO rendering! In order to order tiles correctly we need a chunk per Y layer.
// This is why the map size is 4 on the y but only 1 for chunk size.
let mut map_settings = LayerSettings::new(
MapSize(1, 4),
ChunkSize(4, 1),
MapSize(1, 8),
ChunkSize(8, 1),
TileSize(64.0, 64.0),
TextureSize(384.0, 64.0),
);
Expand All @@ -39,33 +39,6 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query
}
.into(),
);
layer_0.fill(
TilePos(32, 0),
TilePos(64, 32),
Tile {
texture_index: 1,
..Default::default()
}
.into(),
);
layer_0.fill(
TilePos(0, 32),
TilePos(32, 64),
Tile {
texture_index: 2,
..Default::default()
}
.into(),
);
layer_0.fill(
TilePos(32, 32),
TilePos(64, 64),
Tile {
texture_index: 3,
..Default::default()
}
.into(),
);

map_query.build_layer(&mut commands, layer_0, texture_handle.clone());

Expand All @@ -77,7 +50,7 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query

let mut random = thread_rng();

for _ in 0..4 {
for _ in 0..8 {
let position = TilePos(random.gen_range(0..3), random.gen_range(0..3));
// Ignore errors for demo sake.
let _ = layer_builder.set_tile(
Expand All @@ -100,7 +73,7 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>, mut map_query
commands
.entity(map_entity)
.insert(map)
.insert(Transform::from_xyz(0.0, 64.0, 0.0))
.insert(Transform::from_xyz(0.0, 128.0, 0.0))
.insert(GlobalTransform::default());

let x_pos = 0.0;
Expand Down
3 changes: 2 additions & 1 deletion src/layer_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@ where
settings.chunk_size.0 as f32 * settings.grid_size.x,
settings.chunk_size.1 as f32 * settings.grid_size.y,
) + Vec2::new(
chunk_pos.1 as f32 * 2.0 * settings.grid_size.x,
chunk_pos.1 as f32
* (settings.grid_size.x * settings.chunk_size.0 as f32 / 2.0),
-((chunk_pos.1 as f32) * -settings.grid_size.x / 4.0),
)
}
Expand Down

0 comments on commit af750d5

Please sign in to comment.