pub struct Tilemap { /* private fields */ }Implementations§
Source§impl Tilemap
impl Tilemap
pub fn new() -> Self
pub fn require_chunk(&mut self, loc: IVec2)
Sourcepub fn set_tile(
&mut self,
commands: &mut Commands<'_, '_>,
loc: IVec2,
tile: Tile,
additional_components: impl Bundle,
) -> Entity
pub fn set_tile( &mut self, commands: &mut Commands<'_, '_>, loc: IVec2, tile: Tile, additional_components: impl Bundle, ) -> Entity
Examples found in repository?
examples/tilemap.rs (lines 75-80)
57fn placement_system(
58 mut commands: Commands,
59 mut tilemaps: Query<&mut Tilemap>,
60 input: Res<Input<MouseButton>>,
61 keys: Res<Input<KeyCode>>,
62 mouse_pos_resource: Res<MousePosResource>,
63
64 images: Res<Assets<Image>>,
65 tile_resource: Res<TileResource>,
66) {
67 // Now convert to tile coords.
68 let (tile_coord, pixel_coord) = world_unit_to_pixel(mouse_pos_resource.mouse_pos);
69
70 if input.pressed(MouseButton::Left) {
71 let image = images
72 .get(tile_resource.image_handles.get("Lightslate").unwrap())
73 .unwrap();
74 // Set the tile at that location
75 tilemaps.single_mut().set_tile(
76 &mut commands,
77 tile_coord,
78 Tile::from_image(image, (16..24, 16..24)),
79 (),
80 );
81 }
82
83 if input.pressed(MouseButton::Right) {
84 tilemaps.single_mut().delete_tile(tile_coord);
85 }
86
87 if keys.pressed(KeyCode::P) {
88 // Set the tile's pixel to red
89 tilemaps
90 .single_mut()
91 .set_pixel(tile_coord, pixel_coord, Color::RED);
92 }
93
94 if keys.pressed(KeyCode::M) {
95 // Remove the tile at that location
96 let image = images
97 .get(tile_resource.image_handles.get("Lightslate").unwrap())
98 .unwrap();
99
100 let tile = MultiTile::from_image(image);
101 tile.place(tile_coord, &mut tilemaps.single_mut(), &mut commands);
102 }
103}pub fn try_set_tile( &mut self, commands: &mut Commands<'_, '_>, chunks: &Query<'_, '_, &Chunk>, loc: IVec2, tile: Tile, additional_components: impl Bundle, ) -> Option<Entity>
Sourcepub fn set_pixel(&mut self, loc: IVec2, pixel: IVec2, color: Color)
pub fn set_pixel(&mut self, loc: IVec2, pixel: IVec2, color: Color)
Examples found in repository?
examples/tilemap.rs (line 91)
57fn placement_system(
58 mut commands: Commands,
59 mut tilemaps: Query<&mut Tilemap>,
60 input: Res<Input<MouseButton>>,
61 keys: Res<Input<KeyCode>>,
62 mouse_pos_resource: Res<MousePosResource>,
63
64 images: Res<Assets<Image>>,
65 tile_resource: Res<TileResource>,
66) {
67 // Now convert to tile coords.
68 let (tile_coord, pixel_coord) = world_unit_to_pixel(mouse_pos_resource.mouse_pos);
69
70 if input.pressed(MouseButton::Left) {
71 let image = images
72 .get(tile_resource.image_handles.get("Lightslate").unwrap())
73 .unwrap();
74 // Set the tile at that location
75 tilemaps.single_mut().set_tile(
76 &mut commands,
77 tile_coord,
78 Tile::from_image(image, (16..24, 16..24)),
79 (),
80 );
81 }
82
83 if input.pressed(MouseButton::Right) {
84 tilemaps.single_mut().delete_tile(tile_coord);
85 }
86
87 if keys.pressed(KeyCode::P) {
88 // Set the tile's pixel to red
89 tilemaps
90 .single_mut()
91 .set_pixel(tile_coord, pixel_coord, Color::RED);
92 }
93
94 if keys.pressed(KeyCode::M) {
95 // Remove the tile at that location
96 let image = images
97 .get(tile_resource.image_handles.get("Lightslate").unwrap())
98 .unwrap();
99
100 let tile = MultiTile::from_image(image);
101 tile.place(tile_coord, &mut tilemaps.single_mut(), &mut commands);
102 }
103}Sourcepub fn delete_tile(&mut self, loc: IVec2)
pub fn delete_tile(&mut self, loc: IVec2)
Examples found in repository?
examples/tilemap.rs (line 84)
57fn placement_system(
58 mut commands: Commands,
59 mut tilemaps: Query<&mut Tilemap>,
60 input: Res<Input<MouseButton>>,
61 keys: Res<Input<KeyCode>>,
62 mouse_pos_resource: Res<MousePosResource>,
63
64 images: Res<Assets<Image>>,
65 tile_resource: Res<TileResource>,
66) {
67 // Now convert to tile coords.
68 let (tile_coord, pixel_coord) = world_unit_to_pixel(mouse_pos_resource.mouse_pos);
69
70 if input.pressed(MouseButton::Left) {
71 let image = images
72 .get(tile_resource.image_handles.get("Lightslate").unwrap())
73 .unwrap();
74 // Set the tile at that location
75 tilemaps.single_mut().set_tile(
76 &mut commands,
77 tile_coord,
78 Tile::from_image(image, (16..24, 16..24)),
79 (),
80 );
81 }
82
83 if input.pressed(MouseButton::Right) {
84 tilemaps.single_mut().delete_tile(tile_coord);
85 }
86
87 if keys.pressed(KeyCode::P) {
88 // Set the tile's pixel to red
89 tilemaps
90 .single_mut()
91 .set_pixel(tile_coord, pixel_coord, Color::RED);
92 }
93
94 if keys.pressed(KeyCode::M) {
95 // Remove the tile at that location
96 let image = images
97 .get(tile_resource.image_handles.get("Lightslate").unwrap())
98 .unwrap();
99
100 let tile = MultiTile::from_image(image);
101 tile.place(tile_coord, &mut tilemaps.single_mut(), &mut commands);
102 }
103}pub fn delete_without_marker(&mut self, loc: IVec2)
pub fn get_tile( &mut self, loc: IVec2, chunks: &Query<'_, '_, &Chunk>, ) -> Option<Entity>
pub fn get_chunk(&self, loc: IVec2) -> Option<Entity>
pub fn has_chunk(&self, loc: IVec2) -> bool
Trait Implementations§
Source§impl Component for Tilemap
impl Component for Tilemap
Source§type Storage = TableStorage
type Storage = TableStorage
A marker type indicating the storage type used for this component.
This must be either
TableStorage or SparseStorage.Auto Trait Implementations§
impl Freeze for Tilemap
impl RefUnwindSafe for Tilemap
impl Send for Tilemap
impl Sync for Tilemap
impl Unpin for Tilemap
impl UnwindSafe for Tilemap
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
Return the
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId), )
unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
fn get_components(self, func: &mut impl FnMut(StorageType, OwningPtr<'_>))
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates
Self using data from the given World.