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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exclude = ["assets/*", "screenshots/*"]
default = ["render"]
atlas = []
render = []
serde = ["dep:serde"]
serde = ["dep:serde", "bevy/serialize"]

[dependencies]
bevy = { version = "0.16.0-rc.5", default-features = false, features = [
Expand Down
27 changes: 11 additions & 16 deletions examples/accessing_tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
for y in 0..map_size.y {
let tile_pos = TilePos { x, y };
let tile_entity = commands
.spawn(TileBundle {
position: tile_pos,
tilemap_id: TilemapId(tilemap_entity),
..Default::default()
})
.spawn((Tile, tile_pos, TilemapId(tilemap_entity)))
.id();
// Here we let the tile storage component know what tiles we have.
tile_storage.set(&tile_pos, tile_entity);
Expand Down Expand Up @@ -78,21 +74,20 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {

// This is the size of each individual tiles in pixels.
let tile_size = TilemapTileSize { x: 16.0, y: 16.0 };
let grid_size = tile_size.into();
let grid_size = TilemapGridSize::from(tile_size);

// Spawns a tilemap.
// Once the tile storage is inserted onto the tilemap entity it can no longer be accessed.
commands.entity(tilemap_entity).insert((
TilemapBundle {
grid_size,
size: map_size,
storage: tile_storage,
map_type,
texture: TilemapTexture::Single(texture_handle),
tile_size,
anchor: TilemapAnchor::Center,
..Default::default()
},
Tilemap,
grid_size,
map_size,
tile_storage,
map_type,
TilemapTexture::Single(texture_handle),
TilemapMaterial::standard(),
tile_size,
TilemapAnchor::Center,
LastUpdate(0.0),
CurrentColor(1),
));
Expand Down
15 changes: 8 additions & 7 deletions examples/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,17 @@ fn spawn_tilemap(mut commands: Commands, tile_handle_square: Res<TileHandleSquar
let grid_size = GRID_SIZE_SQUARE;
let map_type = TilemapType::Square;

commands.entity(tilemap_entity).insert(TilemapBundle {
commands.entity(tilemap_entity).insert((
Tilemap,
grid_size,
size: map_size,
storage: tile_storage,
texture: TilemapTexture::Single(tile_handle_square.clone()),
map_size,
tile_storage,
TilemapTexture::Single(tile_handle_square.clone()),
TilemapMaterial::standard(),
tile_size,
map_type,
anchor: TilemapAnchor::TopLeft,
..Default::default()
});
TilemapAnchor::TopLeft,
));
}

#[derive(Component)]
Expand Down
42 changes: 21 additions & 21 deletions examples/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bevy::{
};
use bevy_ecs_tilemap::TilemapPlugin;
use bevy_ecs_tilemap::prelude::*;
use bevy_ecs_tilemap::tiles::{AnimatedTile, TileBundle, TilePos, TileStorage, TileTextureIndex};
use bevy_ecs_tilemap::tiles::{AnimatedTile, TilePos, TileStorage, TileTextureIndex};
use rand::seq::IteratorRandom;
use rand::thread_rng;

Expand Down Expand Up @@ -53,16 +53,17 @@ fn create_background(mut commands: Commands, asset_server: Res<AssetServer>) {

let map_type = TilemapType::default();

commands.entity(tilemap_entity).insert(TilemapBundle {
commands.entity(tilemap_entity).insert((
Tilemap,
size,
grid_size,
map_type,
tile_size,
storage: tile_storage,
texture: TilemapTexture::Single(texture_handle),
anchor: TilemapAnchor::Center,
..Default::default()
});
tile_storage,
TilemapTexture::Single(texture_handle),
TilemapMaterial::standard(),
TilemapAnchor::Center,
));
}

fn create_animated_flowers(mut commands: Commands, asset_server: Res<AssetServer>) {
Expand Down Expand Up @@ -90,12 +91,10 @@ fn create_animated_flowers(mut commands: Commands, asset_server: Res<AssetServer
let tile_pos = TilePos { x, y };
let tile_entity = commands
.spawn((
TileBundle {
position: tile_pos,
tilemap_id: TilemapId(tilemap_entity),
texture_index: TileTextureIndex(0),
..Default::default()
},
Tile,
tile_pos,
TilemapId(tilemap_entity),
TileTextureIndex(0),
// To enable animation, we must insert the `AnimatedTile` component on
// each tile that is to be animated.
AnimatedTile {
Expand All @@ -110,17 +109,18 @@ fn create_animated_flowers(mut commands: Commands, asset_server: Res<AssetServer
}
let map_type = TilemapType::Square;

commands.entity(tilemap_entity).insert(TilemapBundle {
size: map_size,
commands.entity(tilemap_entity).insert((
Tilemap,
map_size,
grid_size,
map_type,
tile_size,
storage: tile_storage,
texture: TilemapTexture::Single(texture_handle),
anchor: TilemapAnchor::Center,
transform: Transform::from_xyz(0.0, 0.0, 1.0),
..Default::default()
});
tile_storage,
TilemapTexture::Single(texture_handle),
TilemapMaterial::standard(),
TilemapAnchor::Center,
Transform::from_xyz(0.0, 0.0, 1.0),
));
}

fn startup(mut commands: Commands) {
Expand Down
23 changes: 10 additions & 13 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,27 @@ fn startup(
for y in 0..map_size.y {
let tile_pos = TilePos { x, y };
let tile_entity = commands
.spawn(TileBundle {
position: tile_pos,
tilemap_id: TilemapId(tilemap_entity),
..Default::default()
})
.spawn((Tile, tile_pos, TilemapId(tilemap_entity)))
.id();
tile_storage.set(&tile_pos, tile_entity);
}
}

let tile_size = TilemapTileSize { x: 16.0, y: 16.0 };
let grid_size = tile_size.into();
let grid_size = TilemapGridSize::from(tile_size);
let map_type = TilemapType::default();

commands.entity(tilemap_entity).insert(TilemapBundle {
commands.entity(tilemap_entity).insert((
Tilemap,
grid_size,
map_type,
size: map_size,
storage: tile_storage,
texture: TilemapTexture::Single(texture_handle),
map_size,
tile_storage,
TilemapTexture::Single(texture_handle),
TilemapMaterial::standard(),
tile_size,
anchor: TilemapAnchor::Center,
..Default::default()
});
TilemapAnchor::Center,
));

// Add atlas to array texture loader so it's preprocessed before we need to use it.
// Only used when the atlas feature is off and we are using array textures.
Expand Down
19 changes: 10 additions & 9 deletions examples/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,24 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
);

let tile_size = TilemapTileSize { x: 16.0, y: 16.0 };
let grid_size = tile_size.into();
let grid_size = TilemapGridSize::from(tile_size);
let map_type = TilemapType::default();

commands.entity(tilemap_entity).insert(TilemapBundle {
commands.entity(tilemap_entity).insert((
Tilemap,
grid_size,
map_type,
size: map_size,
storage: tile_storage,
texture: TilemapTexture::Single(texture_handle),
map_size,
tile_storage,
TilemapTexture::Single(texture_handle),
TilemapMaterial::standard(),
tile_size,
anchor: TilemapAnchor::Center,
render_settings: TilemapRenderSettings {
TilemapAnchor::Center,
TilemapRenderSettings {
render_chunk_size: UVec2::new(256, 256),
..Default::default()
},
..Default::default()
});
));
}

fn main() {
Expand Down
25 changes: 11 additions & 14 deletions examples/chunking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ fn spawn_chunk(commands: &mut Commands, asset_server: &AssetServer, chunk_pos: I
for y in 0..CHUNK_SIZE.y {
let tile_pos = TilePos { x, y };
let tile_entity = commands
.spawn(TileBundle {
position: tile_pos,
tilemap_id: TilemapId(tilemap_entity),
..Default::default()
})
.spawn((Tile, tile_pos, TilemapId(tilemap_entity)))
.id();
commands.entity(tilemap_entity).add_child(tile_entity);
tile_storage.set(&tile_pos, tile_entity);
Expand All @@ -38,19 +34,20 @@ fn spawn_chunk(commands: &mut Commands, asset_server: &AssetServer, chunk_pos: I
0.0,
));
let texture_handle: Handle<Image> = asset_server.load("tiles.png");
commands.entity(tilemap_entity).insert(TilemapBundle {
grid_size: TILE_SIZE.into(),
size: CHUNK_SIZE.into(),
storage: tile_storage,
texture: TilemapTexture::Single(texture_handle),
tile_size: TILE_SIZE,
commands.entity(tilemap_entity).insert((
Tilemap,
TilemapGridSize::from(TILE_SIZE),
TilemapSize::from(CHUNK_SIZE),
tile_storage,
TilemapTexture::Single(texture_handle),
TilemapMaterial::standard(),
TILE_SIZE,
transform,
render_settings: TilemapRenderSettings {
TilemapRenderSettings {
render_chunk_size: RENDER_CHUNK_SIZE,
..Default::default()
},
..Default::default()
});
));
}

fn startup(mut commands: Commands) {
Expand Down
19 changes: 10 additions & 9 deletions examples/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,19 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
);

let tile_size = TilemapTileSize { x: 16.0, y: 16.0 };
let grid_size = tile_size.into();
let grid_size = TilemapGridSize::from(tile_size);

commands.entity(tilemap_entity).insert(TilemapBundle {
commands.entity(tilemap_entity).insert((
Tilemap,
grid_size,
size: map_size,
storage: tile_storage,
texture: TilemapTexture::Single(texture_handle),
map_size,
tile_storage,
TilemapTexture::Single(texture_handle),
TilemapMaterial::standard(),
tile_size,
map_type: TilemapType::Square,
anchor: TilemapAnchor::Center,
..Default::default()
});
TilemapType::Square,
TilemapAnchor::Center,
));
}

fn main() {
Expand Down
54 changes: 25 additions & 29 deletions examples/custom_shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn startup(
) {
commands.spawn(Camera2d);

let my_material_handle = MaterialTilemapHandle::from(materials.add(MyMaterial {
let my_material = TilemapMaterial(materials.add(MyMaterial {
brightness: 0.5,
..default()
}));
Expand All @@ -46,22 +46,20 @@ fn startup(
);

let tile_size = TilemapTileSize { x: 16.0, y: 16.0 };
let grid_size = tile_size.into();
let grid_size = TilemapGridSize::from(tile_size);
let map_type = TilemapType::default();

commands
.entity(tilemap_entity)
.insert(MaterialTilemapBundle {
grid_size,
map_type,
size: map_size,
storage: tile_storage,
texture: TilemapTexture::Single(texture_handle.clone()),
tile_size,
anchor: TilemapAnchor::Center,
material: my_material_handle.clone(),
..Default::default()
});
commands.entity(tilemap_entity).insert((
Tilemap,
grid_size,
map_type,
map_size,
tile_storage,
TilemapTexture::Single(texture_handle.clone()),
tile_size,
TilemapAnchor::Center,
my_material.clone(),
));

// Layer 2
let mut tile_storage = TileStorage::empty(map_size);
Expand All @@ -75,20 +73,18 @@ fn startup(
&mut tile_storage,
);

commands
.entity(tilemap_entity)
.insert(MaterialTilemapBundle {
grid_size,
map_type,
size: map_size,
storage: tile_storage,
texture: TilemapTexture::Single(texture_handle),
tile_size: TilemapTileSize { x: 16.0, y: 16.0 },
anchor: TilemapAnchor::Center,
transform: Transform::from_xyz(32.0, 32.0, 1.0),
material: my_material_handle,
..Default::default()
});
commands.entity(tilemap_entity).insert((
Tilemap,
grid_size,
map_type,
map_size,
tile_storage,
TilemapTexture::Single(texture_handle),
TilemapTileSize { x: 16.0, y: 16.0 },
TilemapAnchor::Center,
Transform::from_xyz(32.0, 32.0, 1.0),
my_material,
));
}

fn main() {
Expand Down
Loading