Struct bevy_tilemap::tilemap::Tilemap [−][src]
A Tilemap which maintains chunks and its tiles within.
Implementations
impl Tilemap
[src]
pub fn new(
texture_atlas: Handle<TextureAtlas>,
texture_width: u32,
texture_height: u32
) -> Tilemap
[src]
texture_atlas: Handle<TextureAtlas>,
texture_width: u32,
texture_height: u32
) -> Tilemap
Constructs a new Tilemap with the required texture atlas and default configuration.
This differs from default
in that it requires the texture atlas
handle.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let tilemap = Tilemap::new(texture_atlas_handle, 32, 32);
pub fn builder() -> TilemapBuilder
[src]
Configures the builder with the default settings.
Is equivalent to default
and builder
method in the
tilemap. Start with this then you are able to method chain.
Examples
use bevy_tilemap::prelude::*; let builder = TilemapBuilder::new(); // Equivalent to... let builder = TilemapBuilder::default(); // Or... let builder = Tilemap::builder();
pub fn set_texture_atlas(&mut self, handle: Handle<TextureAtlas>)
[src]
Sets the sprite sheet for use in the tilemap.
This can be used if the need to swap the sprite sheet for another is wanted.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; let mut tilemap = Tilemap::default(); // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); tilemap.set_texture_atlas(texture_atlas_handle);
pub fn texture_atlas(&self) -> &Handle<TextureAtlas>
[src]
Returns a reference of the handle of the texture atlas.
The Handle is used to get the correct sprite sheet that is used for this tilemap with the renderer.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let tilemap = Tilemap::new(texture_atlas_handle, 32, 32); let texture_atlas: &Handle<TextureAtlas> = tilemap.texture_atlas();
pub fn insert_chunk<P: Into<Point2>>(&mut self, point: P) -> TilemapResult<()>
[src]
Constructs a new chunk and stores it at a coordinate position.
It requires that you give it either a point. It then automatically sets both a sized mesh and chunk for use based on the parameters set in the parent tilemap.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let mut tilemap = TilemapBuilder::new() .texture_atlas(texture_atlas_handle) .dimensions(3, 3) .texture_dimensions(32, 32) .finish() .unwrap(); // Add some chunks. assert!(tilemap.insert_chunk((0, 0)).is_ok()); assert!(tilemap.insert_chunk((1, 1)).is_ok()); assert!(tilemap.insert_chunk((-2, -2)).is_err()); assert!(tilemap.contains_chunk((0, 0))); assert!(tilemap.contains_chunk((1, 1))); assert!(!tilemap.contains_chunk((-2, -2)));
Errors
If the point does not exist in the tilemap, an error is returned. This can only be returned if you had set the dimensions on the tilemap.
Also will return an error if the chunk already exists. If this happens and was intentional, it is best to remove the chunk first. This is simply a fail safe without actually returning the chunk as it is meant to be kept internal.
pub fn contains_chunk<P: Into<Point2>>(&mut self, point: P) -> bool
[src]
Returns true
if the chunk is included in the tilemap.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let mut tilemap = Tilemap::new(texture_atlas_handle, 32, 32); assert!(tilemap.insert_chunk((0, 0)).is_ok()); assert!(tilemap.contains_chunk((0, 0))); assert!(!tilemap.contains_chunk((1, 1)));
pub fn add_layer(
&mut self,
layer: TilemapLayer,
sprite_layer: usize
) -> TilemapResult<()>
[src]
&mut self,
layer: TilemapLayer,
sprite_layer: usize
) -> TilemapResult<()>
Adds a layer to the tilemap.
Warning: This is very unwise and costly if there are many chunks in the tilemap. You should only add layers when creating the tilemap. The meshes for every single chunk has to be recalculated!
This method creates a layer across all chunks at the specified Z layer.
For ease of use, it by default makes a layer with a dense
LayerKind
which is ideal for layers full of sprites.
If you want to use a layer that is more performant and less data heavy,
use add_layer_with_kind
with LayerKind::Sparse
.
If the layer is already the specified layer’s kind, then nothing happens.
Errors
If a layer is set and a different layer already exists at that Z layer then an error is returned regarding that. This is done to prevent accidental overwrites of a layer.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let layer = TilemapLayer { kind: LayerKind::Sparse, ..Default::default() }; let mut tilemap = Tilemap::new(texture_atlas_handle, 32, 32); assert!(tilemap.add_layer(layer, 2).is_ok()); assert!(tilemap.add_layer(layer, 2).is_err());
pub fn move_layer(
&mut self,
from_sprite_order: usize,
to_sprite_order: usize
) -> TilemapResult<()>
[src]
&mut self,
from_sprite_order: usize,
to_sprite_order: usize
) -> TilemapResult<()>
Moves a layer from one Z level to another.
Errors
If the destination exists, it will throw an error. Likewise, if the origin does not exist, it also will throw an error.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let mut tilemap = TilemapBuilder::new() .texture_atlas(texture_atlas_handle) .z_layers(3) .texture_dimensions(32, 32) .add_layer(TilemapLayer { kind: LayerKind::Dense, ..Default::default() }, 0) .add_layer(TilemapLayer { kind: LayerKind::Sparse, ..Default::default() }, 3) .finish() .unwrap(); // If we moved this to layer 3, it would instead fail. assert!(tilemap.move_layer(0, 2).is_ok()); assert!(tilemap.move_layer(3, 2).is_err());
pub fn remove_layer(&mut self, z: usize)
[src]
Removes a layer from the tilemap and inner chunks.
Warning: This is destructive if you have tiles that exist on that
layer. If you want to add them back in, better to use the move_layer
method instead.
This method takes in a Z layer which is then flagged for deletion. If the layer already does not exist, it does nothing.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let mut tilemap = Tilemap::new(texture_atlas_handle, 32, 32); tilemap.add_layer(TilemapLayer { kind: LayerKind::Sparse, ..Default::default() }, 1); tilemap.remove_layer(1);
pub fn spawn_chunk<P: Into<Point2>>(&mut self, point: P) -> TilemapResult<()>
[src]
Spawns a chunk at a given index or coordinate.
Does nothing if the chunk does not exist.
Errors
If the coordinate or index is out of bounds.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let mut tilemap = TilemapBuilder::new() .texture_atlas(texture_atlas_handle) .dimensions(1, 1) .texture_dimensions(32, 32) .finish() .unwrap(); tilemap.insert_chunk((0, 0)); // Ideally you should want to set some tiles here else nothing will // display in the render... assert!(tilemap.spawn_chunk((0, 0)).is_ok()); assert!(tilemap.spawn_chunk((1, 1)).is_err()); assert!(tilemap.spawn_chunk((-1, -1)).is_err());
pub fn spawn_chunk_containing_point<P: Into<Point2>>(
&mut self,
point: P
) -> TilemapResult<()>
[src]
&mut self,
point: P
) -> TilemapResult<()>
Spawns a chunk at a given tile point.
Errors
If the coordinate or index is out of bounds or if the chunk does not exist, an error will be returned.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let mut tilemap = TilemapBuilder::new() .texture_atlas(texture_atlas_handle) .chunk_dimensions(32, 32, 1) .texture_dimensions(32, 32) .dimensions(1, 1) .finish() .unwrap(); let point = (15, 15); let sprite_index = 0; let tile = Tile { point, sprite_index, ..Default::default() }; tilemap.insert_tile(tile); assert!(tilemap.spawn_chunk_containing_point(point).is_ok()); assert!(tilemap.spawn_chunk_containing_point((16, 16)).is_err()); assert!(tilemap.spawn_chunk_containing_point((-18, -18)).is_err());
pub fn despawn_chunk<P: Into<Point2>>(&mut self, point: P) -> TilemapResult<()>
[src]
De-spawns a spawned chunk at a given index or coordinate.
If the chunk is not spawned this will result in nothing.
Errors
If the coordinate or index is out of bounds, an error will be returned.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let mut tilemap = TilemapBuilder::new() .texture_atlas(texture_atlas_handle) .dimensions(1, 1) .texture_dimensions(32, 32) .finish() .unwrap(); assert!(tilemap.insert_chunk((0, 0)).is_ok()); // Ideally you should want to set some tiles here else nothing will // display in the render... assert!(tilemap.spawn_chunk((0, 0)).is_ok()); // Later a frame or more on... assert!(tilemap.despawn_chunk((0, 0)).is_ok()); assert!(tilemap.despawn_chunk((-1, -1)).is_err());
pub fn remove_chunk<P: Into<Point2>>(&mut self, point: P) -> TilemapResult<()>
[src]
Destructively removes a chunk at a coordinate position and despawns them if needed.
Internally, this sends an event to the tilemap’s system flagging which chunks must be removed by index and entity. A chunk is not recoverable if this action is done.
Does nothing if the chunk does not exist.
Errors
If the coordinate or index is out of bounds, an error will be returned.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let mut tilemap = TilemapBuilder::new() .texture_atlas(texture_atlas_handle) .dimensions(3, 3) .texture_dimensions(32, 32) .finish() .unwrap(); // Add some chunks. assert!(tilemap.insert_chunk((0, 0)).is_ok()); assert!(tilemap.insert_chunk((1, 1)).is_ok()); assert!(tilemap.remove_chunk((0, 0)).is_ok()); assert!(tilemap.remove_chunk((1, 1)).is_ok()); assert!(tilemap.remove_chunk((-2, -2)).is_err());
pub fn point_to_chunk_point<P: Into<Point2>>(&self, point: P) -> (i32, i32)
[src]
Takes a tile point and changes it into a chunk point.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let mut tilemap = Tilemap::new(texture_atlas_handle, 32, 32); let tile_point = (15, 15); let chunk_point = tilemap.point_to_chunk_point(tile_point); assert_eq!((0, 0), chunk_point); let tile_point = (16, 16); let chunk_point = tilemap.point_to_chunk_point(tile_point); assert_eq!((1, 1), chunk_point); let tile_point = (-16, -16); let chunk_point = tilemap.point_to_chunk_point(tile_point); assert_eq!((-0, -0), chunk_point); let tile_point = (-17, -17); let chunk_point = tilemap.point_to_chunk_point(tile_point); assert_eq!((-1, -1), chunk_point);
pub fn insert_tiles<P, I>(&mut self, tiles: I) -> TilemapResult<()> where
P: Into<Point3>,
I: IntoIterator<Item = Tile<P>>,
[src]
P: Into<Point3>,
I: IntoIterator<Item = Tile<P>>,
Sets many tiles, creating new chunks if needed.
If setting a single tile is more preferable, then use the insert_tile
method instead.
If the chunk does not yet exist, it will create a new one automatically.
Errors
Returns an error if the given coordinate or index is out of bounds, the layer or chunk does not exist. If either the layer or chunk error occurs then creating what is missing will resolve it.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_render::prelude::*; use bevy_sprite::prelude::*; use bevy_tilemap::{prelude::*, chunk::RawTile}; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let mut tilemap = TilemapBuilder::new() .texture_atlas(texture_atlas_handle) .dimensions(1, 1) .texture_dimensions(32, 32) .finish() .unwrap(); tilemap.insert_chunk((0, 0)).unwrap(); let mut tiles = vec![ Tile { point: (1, 1), sprite_index: 0, ..Default::default() }, Tile { point: (2, 2), sprite_index: 1, ..Default::default() }, Tile { point: (3, 3), sprite_index: 2, ..Default::default() }, ]; // Set multiple tiles and unwrap the result tilemap.insert_tiles(tiles).unwrap(); assert_eq!(tilemap.get_tile((1, 1), 0), Some(&RawTile { index: 0, color: Color::WHITE })); assert_eq!(tilemap.get_tile((2, 2), 0), Some(&RawTile { index: 1, color: Color::WHITE })); assert_eq!(tilemap.get_tile((3, 3), 0), Some(&RawTile { index: 2, color: Color::WHITE })); assert_eq!(tilemap.get_tile((4, 4), 0), None);
pub fn insert_tile<P: Into<Point3>>(
&mut self,
tile: Tile<P>
) -> TilemapResult<()>
[src]
&mut self,
tile: Tile<P>
) -> TilemapResult<()>
Sets a single tile at a coordinate position, creating a chunk if necessary.
If you are setting more than one tile at a time, it is highly
recommended not to run this method! If that is preferred, do use
insert_tiles
instead. Every single tile that is created creates a new
event. With bulk tiles, it creates 1 event for all.
If the chunk does not yet exist, it will create a new one automatically.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_render::prelude::*; use bevy_sprite::prelude::*; use bevy_tilemap::{prelude::*, chunk::RawTile}; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let mut tilemap = Tilemap::new(texture_atlas_handle, 32, 32); tilemap.insert_chunk((0, 0)).unwrap(); let point = (9, 3); let sprite_index = 3; let tile = Tile { point, sprite_index, ..Default::default() }; assert!(tilemap.insert_tile(tile).is_ok()); assert_eq!(tilemap.get_tile((9, 3), 0), Some(&RawTile { index: 3, color: Color::WHITE }))
Errors
Returns an error if the given coordinate or index is out of bounds.
pub fn clear_tiles<P, I>(&mut self, points: I) -> TilemapResult<()> where
P: Into<Point3>,
I: IntoIterator<Item = (P, usize)>,
[src]
P: Into<Point3>,
I: IntoIterator<Item = (P, usize)>,
Clears the tiles at the specified points from the tilemap.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_render::prelude::*; use bevy_sprite::prelude::*; use bevy_tilemap::{prelude::*, chunk::RawTile}; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let mut tilemap = Tilemap::new(texture_atlas_handle, 32, 32); assert!(tilemap.insert_chunk((0, 0)).is_ok()); let mut tiles = vec![ Tile { point: (1, 1, 0), ..Default::default() }, Tile { point: (2, 2, 0), ..Default::default() }, Tile { point: (3, 3, 0), ..Default::default() }, ]; // Set multiple tiles and unwrap the result assert!(tilemap.insert_tiles(tiles.clone()).is_ok()); // Then later on... Do note that if this done in the same frame, the // tiles will not even exist at all. let mut to_remove = vec![ ((1, 1), 0), ((2, 2), 0), ]; tilemap.clear_tiles(to_remove).unwrap(); assert_eq!(tilemap.get_tile((1, 1, 0), 0), None); assert_eq!(tilemap.get_tile((2, 2, 0), 0), None); assert_eq!(tilemap.get_tile((3, 3, 0), 0), Some(&RawTile { index: 0, color: Color::WHITE} ));
Errors
An error can occure if the point is outside of the tilemap. This can only happen if the tilemap has dimensions.
pub fn clear_tile<P>(
&mut self,
point: P,
sprite_order: usize
) -> TilemapResult<()> where
P: Into<Point3>,
[src]
&mut self,
point: P,
sprite_order: usize
) -> TilemapResult<()> where
P: Into<Point3>,
Clear a single tile at the specified point from the tilemap.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::{prelude::*, chunk::RawTile}; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let mut tilemap = Tilemap::new(texture_atlas_handle, 32, 32); assert!(tilemap.insert_chunk((0, 0)).is_ok()); let point = (3, 1); let sprite_index = 1; let tile = Tile { point, sprite_index, ..Default::default() }; // Set a single tile and unwrap the result assert!(tilemap.insert_tile(tile).is_ok()); // Later on... assert!(tilemap.clear_tile(point, 0).is_ok()); assert_eq!(tilemap.get_tile((3, 1), 0), None);
Errors
An error can occure if the point is outside of the tilemap. This can only happen if the tilemap has dimensions.
pub fn get_tile<P>(&mut self, point: P, sprite_order: usize) -> Option<&RawTile> where
P: Into<Point3>,
[src]
P: Into<Point3>,
Gets a raw tile from a given point and z order.
This is different thant he usual Tile
struct in that it only
contains the sprite index and the tint.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_render::prelude::*; use bevy_sprite::prelude::*; use bevy_tilemap::{prelude::*, chunk::RawTile}; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let mut tilemap = Tilemap::new(texture_atlas_handle, 32, 32); tilemap.insert_chunk((0, 0)).unwrap(); let point = (9, 3); let sprite_index = 3; let tile = Tile { point, sprite_index, ..Default::default() }; assert!(tilemap.insert_tile(tile).is_ok()); assert_eq!(tilemap.get_tile((9, 3), 0), Some(&RawTile { index: 3, color: Color::WHITE })); assert_eq!(tilemap.get_tile((10, 4), 0), None);
pub fn get_tile_mut<P>(
&mut self,
point: P,
sprite_order: usize
) -> Option<&mut RawTile> where
P: Into<Point3>,
[src]
&mut self,
point: P,
sprite_order: usize
) -> Option<&mut RawTile> where
P: Into<Point3>,
Gets a mutable raw tile from a given point and z order.
This is different thant he usual Tile
struct in that it only
contains the sprite index and the tint.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_render::prelude::*; use bevy_sprite::prelude::*; use bevy_tilemap::{prelude::*, chunk::RawTile}; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let mut tilemap = Tilemap::new(texture_atlas_handle, 32, 32); tilemap.insert_chunk((0, 0)).unwrap(); let point = (2, 5); let sprite_index = 2; let tile = Tile { point, sprite_index, ..Default::default() }; assert!(tilemap.insert_tile(tile).is_ok()); assert_eq!(tilemap.get_tile_mut((2, 5), 0), Some(&mut RawTile { index: 2, color: Color::WHITE })); assert_eq!(tilemap.get_tile_mut((1, 4), 0), None);
pub fn clear_layer(&mut self, layer: usize) -> Result<(), TilemapError>
[src]
Clears a layer of all the tiles.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_render::prelude::*; use bevy_sprite::prelude::*; use bevy_tilemap::{prelude::*, chunk::RawTile}; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let mut tilemap = TilemapBuilder::new() .texture_atlas(texture_atlas_handle) .dimensions(1, 1) .texture_dimensions(32, 32) .add_layer( TilemapLayer { kind: LayerKind::Dense}, 0) .add_layer( TilemapLayer { kind: LayerKind::Sparse}, 1) .finish() .unwrap(); assert!(tilemap.clear_layer(0).is_ok()); assert!(tilemap.clear_layer(1).is_ok()); assert!(tilemap.clear_layer(2).is_err());
Errors
Fails if the layer does not exist.
pub fn center_tile_coord(&self) -> Option<(i32, i32)>
[src]
Returns the center tile, if the tilemap has dimensions.
Returns None
if the tilemap has no constrainted dimensions.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let mut tilemap = TilemapBuilder::new() .texture_atlas(texture_atlas_handle.clone_weak()) .dimensions(32, 32) .texture_dimensions(32, 32) .finish() .unwrap(); let center = tilemap.center_tile_coord(); // 32 * 32 / 2 = 512 assert_eq!(center, Some((512, 512))); let mut tilemap = Tilemap::new(texture_atlas_handle, 32, 32); let center = tilemap.center_tile_coord(); assert_eq!(center, None);
pub fn width(&self) -> Option<u32>
[src]
The width of the tilemap in chunks, if it has dimensions.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let tilemap = TilemapBuilder::new() .texture_atlas(texture_atlas_handle.clone_weak()) .dimensions(32, 64) .texture_dimensions(32, 32) .finish() .unwrap(); let width = tilemap.width(); assert_eq!(width, Some(32)); let tilemap = Tilemap::new(texture_atlas_handle, 32, 32); let width = tilemap.width(); assert_eq!(width, None);
pub fn height(&self) -> Option<u32>
[src]
The height of the tilemap in chunks, if it has dimensions.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let tilemap = TilemapBuilder::new() .texture_atlas(texture_atlas_handle.clone_weak()) .dimensions(32, 64) .texture_dimensions(32, 32) .finish() .unwrap(); let height = tilemap.height(); assert_eq!(height, Some(64)); let tilemap = Tilemap::new(texture_atlas_handle, 32, 32); let height = tilemap.height(); assert_eq!(height, None);
pub fn chunk_width(&self) -> u32
[src]
The width of all the chunks in tiles.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let tilemap = TilemapBuilder::new() .texture_atlas(texture_atlas_handle) .chunk_dimensions(32, 64, 1) .texture_dimensions(32, 32) .finish() .unwrap(); let chunk_width: u32 = tilemap.chunk_width(); assert_eq!(chunk_width, 32);
pub fn chunk_height(&self) -> u32
[src]
The height of all the chunks in tiles.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let tilemap = TilemapBuilder::new() .texture_atlas(texture_atlas_handle) .chunk_dimensions(32, 64, 1) .texture_dimensions(32, 32) .finish() .unwrap(); let chunk_height: u32 = tilemap.chunk_height(); assert_eq!(chunk_height, 64);
pub fn tile_width(&self) -> u32
[src]
The width of a tile in pixels.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let tilemap = TilemapBuilder::new() .texture_atlas(texture_atlas_handle) .texture_dimensions(32, 64) .finish() .unwrap(); let tile_width: u32 = tilemap.tile_width(); assert_eq!(tile_width, 32);
pub fn tile_height(&self) -> u32
[src]
The height of a tile in pixels.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let tilemap = TilemapBuilder::new() .texture_atlas(texture_atlas_handle) .texture_dimensions(32, 64) .finish() .unwrap(); let tile_height: u32 = tilemap.tile_height(); assert_eq!(tile_height, 64);
pub fn topology(&self) -> GridTopology
[src]
The topology of the tilemap grid.
Currently there are 7 topologies which are set with GridTopology
. By
default this is square as it is the most common topology.
Typically, for most situations squares are used for local maps and hex is used for war games or world maps. It is easier to define structures with walls and floors with square but not impossible with hex.
Examples
use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::prelude::*; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let tilemap = TilemapBuilder::new() .texture_atlas(texture_atlas_handle) .topology(GridTopology::HexX) .texture_dimensions(32, 32) .finish() .unwrap(); assert_eq!(tilemap.topology(), GridTopology::HexX);
pub fn chunk_events(&self) -> &Events<TilemapChunkEvent>
[src]
Returns a reference to the tilemap chunk events.
This is handy if it is needed to know when new chunks are created which can then be used to trigger events with other systems. For example, if you have a system that adds tiles procedurally to the chunks, upon a chunk event this can be used to trigger the creation of those tiles.
Examples
use bevy_app::{prelude::*, Events}; use bevy_asset::{prelude::*, HandleId}; use bevy_sprite::prelude::*; use bevy_tilemap::{prelude::*, event::TilemapChunkEvent}; // In production use a strong handle from an actual source. let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>()); let tilemap = Tilemap::new(texture_atlas_handle, 32, 32); let events: &Events<TilemapChunkEvent> = tilemap.chunk_events();
Trait Implementations
impl Debug for Tilemap
[src]
impl Default for Tilemap
[src]
impl<'de> Deserialize<'de> for Tilemap
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Serialize for Tilemap
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl TypeUuid for Tilemap
[src]
Auto Trait Implementations
impl RefUnwindSafe for Tilemap
impl Send for Tilemap
impl Sync for Tilemap
impl Unpin for Tilemap
impl UnwindSafe for Tilemap
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Any for T where
T: Any,
T: Any,
impl<T> Asset for T where
T: TypeUuid + AssetDynamic + TypeUuidDynamic,
[src]
T: TypeUuid + AssetDynamic + TypeUuidDynamic,
impl<T> AssetDynamic for T where
T: Send + Sync + 'static + TypeUuidDynamic,
[src]
T: Send + Sync + 'static + TypeUuidDynamic,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Component for T where
T: 'static + Send + Sync,
[src]
T: 'static + Send + Sync,
impl<T> Component for T where
T: 'static + Send + Sync,
[src]
T: 'static + Send + Sync,
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> Downcast for T where
T: Any,
T: Any,
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn as_any(&self) -> &(dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
impl<T> DowncastSync for T where
T: Any + Send + Sync,
T: Any + Send + Sync,
impl<T> From<T> for T
[src]
impl<T> FromResources for T where
T: Default,
[src]
T: Default,
pub fn from_resources(_resources: &Resources) -> T
[src]
impl<T> FromWorld for T where
T: Default,
[src]
T: Default,
pub fn from_world(_world: &mut World) -> T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Resource for T where
T: 'static + Send + Sync,
[src]
T: 'static + Send + Sync,
impl<T> Serialize for T where
T: Serialize + ?Sized,
[src]
T: Serialize + ?Sized,
pub fn erased_serialize(
&self,
serializer: &mut dyn Serializer
) -> Result<Ok, Error>
[src]
&self,
serializer: &mut dyn Serializer
) -> Result<Ok, Error>
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> TypeUuidDynamic for T where
T: TypeUuid,
[src]
T: TypeUuid,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,