Struct bevy_pixel_map::tile::Tile
source · 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
Examples found in repository?
More examples
examples/tilemap.rs (line 51)
43 44 45 46 47 48 49 50 51 52 53 54 55 56
pub fn set_tons_of_tiles(mut commands: Commands, mut tilemaps: Query<&mut Tilemap>) {
let mut tilemap = tilemaps.get_single_mut().unwrap();
for x in -64..64 {
for y in -64..64 {
tilemap.set_tile(
&mut commands,
IVec2::new(x, y),
Tile::from_color(Color::rgba(1.0, 1.0, 1.0, 1.0)),
(),
);
}
}
}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 83)
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
fn placement_system(
mut commands: Commands,
mut tilemaps: Query<&mut Tilemap>,
input: Res<Input<MouseButton>>,
windows: Query<&Window, With<PrimaryWindow>>,
cameras: Query<(&Camera, &GlobalTransform)>,
images: Res<Assets<Image>>,
tile_resource: Res<TileResource>,
) {
if let Some(mouse_pos) = windows.single().cursor_position() {
let (camera, trans) = cameras.single();
let mouse_location = camera.viewport_to_world_2d(trans, mouse_pos).unwrap();
// Now convert to tile coords.
let tile_coord = world_unit_to_tile(mouse_location);
if input.pressed(MouseButton::Left) {
let image = images
.get(tile_resource.image_handles.get("Lightslate").unwrap())
.unwrap();
// Set the tile at that location
tilemaps.single_mut().set_tile(
&mut commands,
tile_coord,
Tile::from_image(image, (16..24, 16..24)),
(),
);
}
if input.pressed(MouseButton::Right) {
// Remove the tile at that location
let image = images
.get(tile_resource.image_handles.get("Lightslate").unwrap())
.unwrap();
let tile = MultiTile::from_image(image);
tile.place(tile_coord, &mut tilemaps.single_mut(), &mut commands);
}
}
}pub fn get_pixel(&self, loc: IVec2) -> Option<Color>
pub fn pixel_count(&self) -> usize
Trait Implementations§
source§impl PartialEq for Tile
impl PartialEq for Tile
impl StructuralPartialEq for Tile
Auto Trait Implementations§
impl RefUnwindSafe for Tile
impl Send for Tile
impl Sync for Tile
impl Unpin for Tile
impl UnwindSafe for Tile
Blanket Implementations§
§impl<T, U> AsBindGroupShaderType<U> for Twhere
U: ShaderType,
&'a T: for<'a> Into<U>,
impl<T, U> AsBindGroupShaderType<U> for Twhere U: ShaderType, &'a T: for<'a> Into<U>,
§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
§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) -> Cwhere F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a>,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§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.§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.§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.§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.