Struct bevy_pixel_map::tile::Tile

source ·
pub struct Tile { /* private fields */ }

Implementations§

source§

impl Tile

source

pub fn from_color(color: Color) -> Self

Examples found in repository?
examples/chunk.rs (line 27)
26
27
28
29
30
31
32
pub fn set_tons_of_tiles(mut commands: Commands, mut chunks: Query<(Entity, &mut Chunk)>) {
    let mut tile = Tile::from_color(Color::rgba(1.0, 1.0, 1.0, 1.0));
    tile.set_pixel(IVec2::new(1, 5), Color::rgba(0.0, 1.0, 0.0, 1.0));
    for (entity, mut chunk) in &mut chunks {
        chunk.set_tile(entity, IVec2::new(3, 2), tile.clone(), (), &mut commands);
    }
}
More examples
Hide additional 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)),
                (),
            );
        }
    }
}
source

pub fn from_pixels(pixels: [[Color; 8]; 8]) -> Self

source

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);
        }
    }
}
source

pub fn set_pixel(&mut self, loc: IVec2, color: Color)

Examples found in repository?
examples/chunk.rs (line 28)
26
27
28
29
30
31
32
pub fn set_tons_of_tiles(mut commands: Commands, mut chunks: Query<(Entity, &mut Chunk)>) {
    let mut tile = Tile::from_color(Color::rgba(1.0, 1.0, 1.0, 1.0));
    tile.set_pixel(IVec2::new(1, 5), Color::rgba(0.0, 1.0, 0.0, 1.0));
    for (entity, mut chunk) in &mut chunks {
        chunk.set_tile(entity, IVec2::new(3, 2), tile.clone(), (), &mut commands);
    }
}
source

pub fn get_pixel(&self, loc: IVec2) -> Option<Color>

source

pub fn pixel_count(&self) -> usize

Trait Implementations§

source§

impl Clone for Tile

source§

fn clone(&self) -> Tile

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Component for Tilewhere Self: Send + Sync + 'static,

§

type Storage = TableStorage

A marker type indicating the storage type used for this component. This must be either [TableStorage] or [SparseStorage].
source§

impl Debug for Tile

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for Tile

source§

fn eq(&self, other: &Tile) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

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> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

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<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for Twhere T: 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>

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)

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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for Twhere T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
§

impl<C> DynamicBundle for Cwhere C: Component,

§

fn get_components(self, func: &mut impl FnMut(StorageType, OwningPtr<'_>))

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> TypeData for Twhere T: 'static + Send + Sync + Clone,

§

fn clone_type_data(&self) -> Box<dyn TypeData>

§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,