Tilemap chunking part 2
This commit is contained in:
+10
-12
@@ -1,4 +1,3 @@
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
mod camera;
|
||||
@@ -27,7 +26,6 @@ fn main() {
|
||||
)
|
||||
.insert_resource(ClearColor(Color::srgb(0.0, 0.0, 0.0)))
|
||||
.add_plugins(tilemap::TilemapPlugin)
|
||||
.add_plugins(tilemap::OcclusionPlugin)
|
||||
.add_systems(
|
||||
Startup,
|
||||
(
|
||||
@@ -61,14 +59,14 @@ fn main() {
|
||||
|
||||
fn setup_initial_chunks(mut event_writer: EventWriter<tilemap::LoadChunkEvent>) {
|
||||
println!("setup_initial_chunks");
|
||||
// Spawn a 3x3 grid of chunks around the origin
|
||||
for x in -1..=1 {
|
||||
for y in -1..=1 {
|
||||
event_writer.send(tilemap::LoadChunkEvent {
|
||||
chunk_position: IVec2::new(x, y),
|
||||
});
|
||||
}
|
||||
}
|
||||
// // Spawn a 3x3 grid of chunks around the origin
|
||||
// for x in -5..=5 {
|
||||
// for y in -5..=5 {
|
||||
// event_writer.send(tilemap::LoadChunkEvent {
|
||||
// chunk_position: IVec2::new(x, y),
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// New system to check camera position and load nearby chunks
|
||||
@@ -87,8 +85,8 @@ fn check_camera_position_for_chunks(
|
||||
(camera_pos.y / (tilemap::CHUNK_SIZE as f32 * constants::TILE_SIZE)).floor() as i32;
|
||||
|
||||
// Check a 3x3 area around the camera's current chunk
|
||||
for x in (chunk_x - 1)..=(chunk_x + 1) {
|
||||
for y in (chunk_y - 1)..=(chunk_y + 1) {
|
||||
for x in (chunk_x - 2)..=(chunk_x + 2) {
|
||||
for y in (chunk_y - 2)..=(chunk_y + 2) {
|
||||
let chunk_pos = IVec2::new(x, y);
|
||||
|
||||
// Only spawn new chunks if they haven't been loaded yet
|
||||
|
||||
Reference in New Issue
Block a user