pub enum ImageSampler {
Default,
Descriptor(ImageSamplerDescriptor),
}Expand description
Used in Image, this determines what image sampler to use when rendering. The default setting,
ImageSampler::Default, will read the sampler from the ImagePlugin at setup.
Setting this to ImageSampler::Descriptor will override the global default descriptor for this Image.
Variants§
Default
Default image sampler, derived from the ImagePlugin setup.
Descriptor(ImageSamplerDescriptor)
Custom sampler for this image which will override global default.
Implementations§
Source§impl ImageSampler
impl ImageSampler
Sourcepub fn linear() -> ImageSampler
pub fn linear() -> ImageSampler
Returns an image sampler with ImageFilterMode::Linear min and mag filters
Sourcepub fn nearest() -> ImageSampler
pub fn nearest() -> ImageSampler
Returns an image sampler with ImageFilterMode::Nearest min and mag filters
Examples found in repository?
17fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
18 let image = asset_server.load_with_settings(
19 "textures/fantasy_ui_borders/numbered_slices.png",
20 |settings: &mut ImageLoaderSettings| {
21 // Need to use nearest filtering to avoid bleeding between the slices with tiling
22 settings.sampler = ImageSampler::nearest();
23 },
24 );
25
26 let slicer = TextureSlicer {
27 // `numbered_slices.png` is 48 pixels square. `BorderRect::square(16.)` insets the slicing line from each edge by 16 pixels, resulting in nine slices that are each 16 pixels square.
28 border: BorderRect::all(16.),
29 // With `SliceScaleMode::Tile` the side and center slices are tiled to fill the side and center sections of the target.
30 // And with a `stretch_value` of `1.` the tiles will have the same size as the corresponding slices in the source image.
31 center_scale_mode: SliceScaleMode::Tile { stretch_value: 1. },
32 sides_scale_mode: SliceScaleMode::Tile { stretch_value: 1. },
33 ..default()
34 };
35
36 // ui camera
37 commands.spawn(Camera2d);
38
39 commands
40 .spawn(Node {
41 width: percent(100),
42 height: percent(100),
43 justify_content: JustifyContent::Center,
44 align_content: AlignContent::Center,
45 flex_wrap: FlexWrap::Wrap,
46 column_gap: px(10),
47 row_gap: px(10),
48 ..default()
49 })
50 .with_children(|parent| {
51 for [columns, rows] in [[3, 3], [4, 4], [5, 4], [4, 5], [5, 5]] {
52 for (flip_x, flip_y) in [(false, false), (false, true), (true, false), (true, true)]
53 {
54 parent.spawn((
55 ImageNode {
56 image: image.clone(),
57 flip_x,
58 flip_y,
59 image_mode: NodeImageMode::Sliced(slicer.clone()),
60 ..default()
61 },
62 Node {
63 width: px(16 * columns),
64 height: px(16 * rows),
65 ..default()
66 },
67 ));
68 }
69 }
70 });
71}More examples
21fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
22 // Without any .meta file specifying settings, the default sampler [ImagePlugin::default()] is used for loading images.
23 // If you are using a very small image and rendering it larger like seen here, the default linear filtering will result in a blurry image.
24 // Useful note: The default sampler specified by the ImagePlugin is *not* the same as the default implementation of sampler. This is why
25 // everything uses linear by default but if you look at the default of sampler, it uses nearest.
26 commands.spawn((
27 Sprite {
28 image: asset_server.load("bevy_pixel_dark.png"),
29 custom_size: Some(Vec2 { x: 160.0, y: 120.0 }),
30 ..Default::default()
31 },
32 Transform::from_xyz(-100.0, 0.0, 0.0),
33 ));
34
35 // When a .meta file is added with the same name as the asset and a '.meta' extension
36 // you can (and must) specify all fields of the asset loader's settings for that
37 // particular asset, in this case [ImageLoaderSettings]. Take a look at
38 // examples/asset/files/bevy_pixel_dark_with_meta.png.meta
39 // for the format and you'll notice, the only non-default option is setting Nearest
40 // filtering. This tends to work much better for pixel art assets.
41 // A good reference when filling this out is to check out [ImageLoaderSettings::default()]
42 // and follow to the default implementation of each fields type.
43 // https://docs.rs/bevy/latest/bevy/image/struct.ImageLoaderSettings.html
44 commands.spawn((
45 Sprite {
46 image: asset_server.load("bevy_pixel_dark_with_meta.png"),
47 custom_size: Some(Vec2 { x: 160.0, y: 120.0 }),
48 ..Default::default()
49 },
50 Transform::from_xyz(100.0, 0.0, 0.0),
51 ));
52
53 // Another option is to use the AssetServers load_with_settings function.
54 // With this you can specify the same settings upon loading your asset with a
55 // couple of differences. A big one is that you aren't required to set *every*
56 // setting, just modify the ones that you need. It works by passing in a function
57 // (in this case an anonymous closure) that takes a reference to the settings type
58 // that is then modified in the function.
59 // Do note that if you want to load the same asset with different settings, the
60 // settings changes from any loads after the first of the same asset will be ignored.
61 // This is why this one loads a differently named copy of the asset instead of using
62 // same one as without a .meta file.
63 commands.spawn((
64 Sprite {
65 image: asset_server.load_with_settings(
66 "bevy_pixel_dark_with_settings.png",
67 |settings: &mut ImageLoaderSettings| {
68 settings.sampler = ImageSampler::nearest();
69 },
70 ),
71 custom_size: Some(Vec2 { x: 160.0, y: 120.0 }),
72 ..Default::default()
73 },
74 Transform::from_xyz(0.0, 150.0, 0.0),
75 ));
76
77 commands.spawn(Camera2d);
78}Sourcepub fn get_or_init_descriptor(&mut self) -> &mut ImageSamplerDescriptor
pub fn get_or_init_descriptor(&mut self) -> &mut ImageSamplerDescriptor
Initialize the descriptor if it is not already initialized.
Descriptor is typically initialized by Bevy when the image is loaded, so this is convenient shortcut for updating the descriptor.
Trait Implementations§
Source§impl Clone for ImageSampler
impl Clone for ImageSampler
Source§fn clone(&self) -> ImageSampler
fn clone(&self) -> ImageSampler
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ImageSampler
impl Debug for ImageSampler
Source§impl Default for ImageSampler
impl Default for ImageSampler
Source§fn default() -> ImageSampler
fn default() -> ImageSampler
Source§impl<'de> Deserialize<'de> for ImageSampler
impl<'de> Deserialize<'de> for ImageSampler
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ImageSampler, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ImageSampler, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for ImageSampler
impl PartialEq for ImageSampler
Source§impl Serialize for ImageSampler
impl Serialize for ImageSampler
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for ImageSampler
Auto Trait Implementations§
impl Freeze for ImageSampler
impl RefUnwindSafe for ImageSampler
impl Send for ImageSampler
impl Sync for ImageSampler
impl Unpin for ImageSampler
impl UnsafeUnpin for ImageSampler
impl UnwindSafe for ImageSampler
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<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
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
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>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn 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>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which 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)
&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)
&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> 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>
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>
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)
&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)
&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> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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 default().
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Source§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
Source§impl<Ret> SpawnIfAsync<(), Ret> for Ret
impl<Ret> SpawnIfAsync<(), Ret> for Ret
Source§impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
Source§fn super_from(input: T) -> O
fn super_from(input: T) -> O
Source§impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
Source§fn super_into(self) -> O
fn super_into(self) -> O
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.