pub struct Tile { /* private fields */ }Implementations§
Source§impl Tile
impl Tile
Sourcepub fn from_color(color: Color) -> Self
pub fn from_color(color: Color) -> Self
pub fn from_pixels(pixels: [[Color; 8]; 8]) -> Self
Sourcepub fn from_image(
image: &Image,
pixel_range: (Range<usize>, Range<usize>),
) -> Self
pub fn from_image( image: &Image, pixel_range: (Range<usize>, Range<usize>), ) -> Self
Examples found in repository?
examples/tilemap.rs (line 78)
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 get_pixel(&self, loc: IVec2) -> Option<Color>
pub fn pixel_count(&self) -> usize
Trait Implementations§
Source§impl Component for Tile
impl Component for Tile
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.impl StructuralPartialEq for Tile
Auto Trait Implementations§
impl Freeze for Tile
impl RefUnwindSafe for Tile
impl Send for Tile
impl Sync for Tile
impl Unpin for Tile
impl UnwindSafe for Tile
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.