pub struct Sprite {
pub image: Handle<Image>,
pub texture_atlas: Option<TextureAtlas>,
pub color: Color,
pub flip_x: bool,
pub flip_y: bool,
pub custom_size: Option<Vec2>,
pub rect: Option<Rect>,
pub image_mode: SpriteImageMode,
pub alpha_mode: SpriteAlphaMode,
}bevy_sprite only.Expand description
Describes a sprite to be rendered to a 2D camera
Fields§
§image: Handle<Image>The image used to render the sprite
texture_atlas: Option<TextureAtlas>The (optional) texture atlas used to render the sprite
color: ColorThe sprite’s color tint
flip_x: boolFlip the sprite along the X axis
flip_y: boolFlip the sprite along the Y axis
custom_size: Option<Vec2>An optional custom size for the sprite that will be used when rendering, instead of the size of the sprite’s image
rect: Option<Rect>An optional rectangle representing the region of the sprite’s image to render, instead of rendering
the full image. This is an easy one-off alternative to using a TextureAtlas.
When used with a TextureAtlas, the rect
is offset by the atlas’s minimal (top-left) corner position.
image_mode: SpriteImageModeHow the sprite’s image will be scaled.
alpha_mode: SpriteAlphaModeThe sprite’s alpha mode, defaulting to Blend.
Implementations§
Source§impl Sprite
impl Sprite
Sourcepub fn sized(custom_size: Vec2) -> Sprite
pub fn sized(custom_size: Vec2) -> Sprite
Create a Sprite with a custom size
Examples found in repository?
73fn spawn_curve_sprite<T: CurveColor>(commands: &mut Commands, y: f32, points: [T; 4]) {
74 commands.spawn((
75 Sprite::sized(Vec2::new(75., 75.)),
76 Transform::from_xyz(0., y, 0.),
77 Curve(CubicBezier::new([points]).to_curve().unwrap()),
78 ));
79}
80
81fn spawn_mixed_sprite<T: MixedColor>(commands: &mut Commands, y: f32, colors: [T; 4]) {
82 commands.spawn((
83 Transform::from_xyz(0., y, 0.),
84 Sprite::sized(Vec2::new(75., 75.)),
85 Mixed(colors),
86 ));
87}Sourcepub fn from_image(image: Handle<Image>) -> Sprite
pub fn from_image(image: Handle<Image>) -> Sprite
Create a sprite from an image
Examples found in repository?
More examples
- examples/2d/move_sprite.rs
- examples/2d/rotate_to_cursor.rs
- examples/camera/pan_camera_controller.rs
- examples/state/sub_states.rs
- examples/asset/web_asset.rs
- examples/2d/pixel_grid_snap.rs
- examples/asset/extra_source.rs
- examples/ecs/parallel_query.rs
- examples/2d/transparency_2d.rs
- examples/asset/embedded_asset.rs
- examples/ecs/hierarchy.rs
- examples/state/custom_transitions.rs
- examples/asset/alter_sprite.rs
- examples/2d/rotation.rs
- examples/2d/cpu_draw.rs
- examples/time/virtual_time.rs
- examples/showcase/desk_toy.rs
- examples/2d/texture_atlas.rs
Sourcepub fn from_atlas_image(image: Handle<Image>, atlas: TextureAtlas) -> Sprite
pub fn from_atlas_image(image: Handle<Image>, atlas: TextureAtlas) -> Sprite
Create a sprite from an image, with an associated texture atlas
Examples found in repository?
251fn create_sprite_from_atlas(
252 commands: &mut Commands,
253 translation: (f32, f32, f32),
254 atlas_texture: Handle<Image>,
255 atlas_sources: TextureAtlasSources,
256 atlas_handle: Handle<TextureAtlasLayout>,
257 vendor_handle: &Handle<Image>,
258) {
259 commands.spawn((
260 Transform {
261 translation: Vec3::new(translation.0, translation.1, translation.2),
262 scale: Vec3::splat(3.0),
263 ..default()
264 },
265 Sprite::from_atlas_image(
266 atlas_texture,
267 atlas_sources.handle(atlas_handle, vendor_handle).unwrap(),
268 ),
269 ));
270}More examples
42fn setup(
43 mut commands: Commands,
44 asset_server: Res<AssetServer>,
45 mut texture_atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
46) {
47 let texture = asset_server.load("textures/rpg/chars/gabe/gabe-idle-run.png");
48 let layout = TextureAtlasLayout::from_grid(UVec2::splat(24), 7, 1, None, None);
49 let texture_atlas_layout = texture_atlas_layouts.add(layout);
50 // Use only the subset of sprites in the sheet that make up the run animation
51 let animation_indices = AnimationIndices { first: 1, last: 6 };
52
53 commands.spawn(Camera2d);
54
55 commands.spawn((
56 Sprite::from_atlas_image(
57 texture,
58 TextureAtlas {
59 layout: texture_atlas_layout,
60 index: animation_indices.first,
61 },
62 ),
63 Transform::from_scale(Vec3::splat(6.0)),
64 animation_indices,
65 AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
66 ));
67}122fn setup_atlas(
123 mut commands: Commands,
124 asset_server: Res<AssetServer>,
125 mut texture_atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
126) {
127 let texture_handle = asset_server.load("textures/rpg/chars/gabe/gabe-idle-run.png");
128 let layout = TextureAtlasLayout::from_grid(UVec2::new(24, 24), 7, 1, None, None);
129 let texture_atlas_layout_handle = texture_atlas_layouts.add(layout);
130 // Use only the subset of sprites in the sheet that make up the run animation
131 let animation_indices = AnimationIndices { first: 1, last: 6 };
132 commands
133 .spawn((
134 Sprite::from_atlas_image(
135 texture_handle,
136 TextureAtlas {
137 layout: texture_atlas_layout_handle,
138 index: animation_indices.first,
139 },
140 ),
141 Transform::from_xyz(300.0, 0.0, 0.0).with_scale(Vec3::splat(6.0)),
142 animation_indices,
143 AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
144 Pickable::default(),
145 ))
146 .observe(recolor_on::<PointerOver>(Color::srgb(0.0, 1.0, 1.0)))
147 .observe(recolor_on::<PointerOut>(Color::srgb(1.0, 1.0, 1.0)))
148 .observe(recolor_on::<PointerPress>(Color::srgb(1.0, 1.0, 0.0)))
149 .observe(recolor_on::<PointerRelease>(Color::srgb(0.0, 1.0, 1.0)));
150}135fn setup_texture_atlas(
136 mut commands: Commands,
137 asset_server: Res<AssetServer>,
138 mut texture_atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
139) {
140 let gabe = asset_server.load("textures/rpg/chars/gabe/gabe-idle-run.png");
141 let animation_indices_gabe = AnimationIndices { first: 0, last: 6 };
142 let gabe_atlas = TextureAtlas {
143 layout: texture_atlas_layouts.add(TextureAtlasLayout::from_grid(
144 UVec2::splat(24),
145 7,
146 1,
147 None,
148 None,
149 )),
150 index: animation_indices_gabe.first,
151 };
152
153 let sprite_sheets = [
154 SpriteSheet {
155 size: Vec2::new(120., 50.),
156 text: "Stretched".to_string(),
157 transform: Transform::from_translation(Vec3::new(-570., -200., 0.)),
158 texture: gabe.clone(),
159 image_mode: SpriteImageMode::Auto,
160 atlas: gabe_atlas.clone(),
161 indices: animation_indices_gabe.clone(),
162 timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
163 },
164 SpriteSheet {
165 size: Vec2::new(120., 50.),
166 text: "Fill Center".to_string(),
167 transform: Transform::from_translation(Vec3::new(-570., -300., 0.)),
168 texture: gabe.clone(),
169 image_mode: SpriteImageMode::Scale(SpriteScalingMode::FillCenter),
170 atlas: gabe_atlas.clone(),
171 indices: animation_indices_gabe.clone(),
172 timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
173 },
174 SpriteSheet {
175 size: Vec2::new(120., 50.),
176 text: "Fill Start".to_string(),
177 transform: Transform::from_translation(Vec3::new(-430., -200., 0.)),
178 texture: gabe.clone(),
179 image_mode: SpriteImageMode::Scale(SpriteScalingMode::FillStart),
180 atlas: gabe_atlas.clone(),
181 indices: animation_indices_gabe.clone(),
182 timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
183 },
184 SpriteSheet {
185 size: Vec2::new(120., 50.),
186 text: "Fill End".to_string(),
187 transform: Transform::from_translation(Vec3::new(-430., -300., 0.)),
188 texture: gabe.clone(),
189 image_mode: SpriteImageMode::Scale(SpriteScalingMode::FillEnd),
190 atlas: gabe_atlas.clone(),
191 indices: animation_indices_gabe.clone(),
192 timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
193 },
194 SpriteSheet {
195 size: Vec2::new(50., 120.),
196 text: "Fill Center".to_string(),
197 transform: Transform::from_translation(Vec3::new(-300., -250., 0.)),
198 texture: gabe.clone(),
199 image_mode: SpriteImageMode::Scale(SpriteScalingMode::FillCenter),
200 atlas: gabe_atlas.clone(),
201 indices: animation_indices_gabe.clone(),
202 timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
203 },
204 SpriteSheet {
205 size: Vec2::new(50., 120.),
206 text: "Fill Start".to_string(),
207 transform: Transform::from_translation(Vec3::new(-190., -250., 0.)),
208 texture: gabe.clone(),
209 image_mode: SpriteImageMode::Scale(SpriteScalingMode::FillStart),
210 atlas: gabe_atlas.clone(),
211 indices: animation_indices_gabe.clone(),
212 timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
213 },
214 SpriteSheet {
215 size: Vec2::new(50., 120.),
216 text: "Fill End".to_string(),
217 transform: Transform::from_translation(Vec3::new(-90., -250., 0.)),
218 texture: gabe.clone(),
219 image_mode: SpriteImageMode::Scale(SpriteScalingMode::FillEnd),
220 atlas: gabe_atlas.clone(),
221 indices: animation_indices_gabe.clone(),
222 timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
223 },
224 SpriteSheet {
225 size: Vec2::new(120., 50.),
226 text: "Fit Center".to_string(),
227 transform: Transform::from_translation(Vec3::new(20., -200., 0.)),
228 texture: gabe.clone(),
229 image_mode: SpriteImageMode::Scale(SpriteScalingMode::FitCenter),
230 atlas: gabe_atlas.clone(),
231 indices: animation_indices_gabe.clone(),
232 timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
233 },
234 SpriteSheet {
235 size: Vec2::new(120., 50.),
236 text: "Fit Start".to_string(),
237 transform: Transform::from_translation(Vec3::new(20., -300., 0.)),
238 texture: gabe.clone(),
239 image_mode: SpriteImageMode::Scale(SpriteScalingMode::FitStart),
240 atlas: gabe_atlas.clone(),
241 indices: animation_indices_gabe.clone(),
242 timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
243 },
244 SpriteSheet {
245 size: Vec2::new(120., 50.),
246 text: "Fit End".to_string(),
247 transform: Transform::from_translation(Vec3::new(160., -200., 0.)),
248 texture: gabe.clone(),
249 image_mode: SpriteImageMode::Scale(SpriteScalingMode::FitEnd),
250 atlas: gabe_atlas.clone(),
251 indices: animation_indices_gabe.clone(),
252 timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
253 },
254 ];
255
256 for sprite_sheet in sprite_sheets {
257 commands.spawn((
258 Sprite {
259 image_mode: sprite_sheet.image_mode,
260 custom_size: Some(sprite_sheet.size),
261 ..Sprite::from_atlas_image(sprite_sheet.texture.clone(), sprite_sheet.atlas.clone())
262 },
263 sprite_sheet.indices,
264 sprite_sheet.timer,
265 sprite_sheet.transform,
266 children![(
267 Text2d::new(sprite_sheet.text),
268 TextLayout::justify(Justify::Center),
269 TextFont::from_font_size(15.),
270 Transform::from_xyz(0., -0.5 * sprite_sheet.size.y - 10., 0.),
271 bevy::sprite::Anchor::TOP_CENTER,
272 )],
273 ));
274 }
275}Sourcepub fn from_color(color: impl Into<Color>, size: Vec2) -> Sprite
pub fn from_color(color: impl Into<Color>, size: Vec2) -> Sprite
Create a sprite from a solid color
Examples found in repository?
21fn spawn(mut commands: Commands) {
22 commands.spawn(Camera2d);
23 for x in -5..=5 {
24 for y in -5..=5 {
25 commands.spawn((
26 BlinkySquare,
27 Transform::from_xyz(x as f32 * 50.0, y as f32 * 50.0, 0.0),
28 Sprite::from_color(Color::BLACK, SQUARE_SIZE),
29 ));
30 }
31 }
32}
33
34fn click(
35 click: On<PointerClick>,
36 mut commands: Commands,
37 squares: Query<(Entity, &Transform), With<BlinkySquare>>,
38 cameras: Query<(&Camera, &GlobalTransform)>,
39) {
40 let (camera, camera_transform) = cameras.single().unwrap();
41 let mut delayed = commands.delayed();
42 for (entity, transform) in squares.iter() {
43 // convert the pointer position to world position
44 let mouse_world_pos = camera
45 .viewport_to_world_2d(camera_transform, click.pointer.position)
46 .unwrap();
47
48 // delay the blinkiness by distance to cursor
49 let dist = mouse_world_pos.distance(transform.translation.truncate());
50 let delay = dist / 1000.0;
51 delayed
52 .secs(delay)
53 .entity(entity)
54 .insert(Sprite::from_color(Color::WHITE, SQUARE_SIZE));
55 delayed
56 .secs(delay + 0.1)
57 .entity(entity)
58 .insert(Sprite::from_color(Color::BLACK, SQUARE_SIZE));
59 }
60}More examples
62fn setup_2d(mut commands: Commands) {
63 commands.spawn((
64 Camera2d,
65 Camera {
66 // render the 2d camera after the 3d camera
67 order: 1,
68 // do not use a clear color
69 clear_color: ClearColorConfig::None,
70 ..default()
71 },
72 ));
73 commands.spawn(Sprite::from_color(
74 Color::srgb(0.25, 0.25, 0.75),
75 Vec2::new(50.0, 50.0),
76 ));
77}138fn setup_2d(mut commands: Commands) {
139 commands.spawn((
140 Camera2d,
141 Camera {
142 // render the 2d camera after the 3d camera
143 order: 1,
144 // do not use a clear color
145 clear_color: ClearColorConfig::None,
146 ..default()
147 },
148 ));
149 commands.spawn(Sprite::from_color(
150 Color::srgb(0.25, 0.25, 0.75),
151 Vec2::new(50.0, 50.0),
152 ));
153}143 fn new(location: WallLocation) -> (Wall, Sprite, Transform) {
144 (
145 Wall,
146 Sprite::from_color(WALL_COLOR, Vec2::ONE),
147 Transform {
148 // We need to convert our Vec2 into a Vec3, by giving it a z-coordinate
149 // This is used to determine the order of our sprites
150 translation: location.position().extend(0.0),
151 // The z-scale of 2D objects must always be 1.0,
152 // or their ordering will be affected in surprising ways.
153 // See https://github.com/bevyengine/bevy/issues/4149
154 scale: location.size().extend(1.0),
155 ..default()
156 },
157 )
158 }
159}
160
161// This resource tracks the game's score
162#[derive(Resource, Deref, DerefMut)]
163struct Score(usize);
164
165#[derive(Component)]
166struct ScoreboardUi;
167
168// Add the game's entities to our world
169fn setup(
170 mut commands: Commands,
171 mut meshes: ResMut<Assets<Mesh>>,
172 mut materials: ResMut<Assets<ColorMaterial>>,
173 asset_server: Res<AssetServer>,
174) {
175 // Camera
176 commands.spawn(Camera2d);
177
178 // Sound
179 let ball_collision_sound = asset_server.load("sounds/breakout_collision.ogg");
180 commands.insert_resource(CollisionSound(ball_collision_sound));
181
182 // Paddle
183 let paddle_y = BOTTOM_WALL + GAP_BETWEEN_PADDLE_AND_FLOOR;
184
185 commands.spawn((
186 Sprite::from_color(PADDLE_COLOR, Vec2::ONE),
187 Transform {
188 translation: Vec3::new(0.0, paddle_y, 0.0),
189 scale: PADDLE_SIZE.extend(1.0),
190 ..default()
191 },
192 Paddle,
193 Collider,
194 ));
195
196 // Ball
197 commands.spawn((
198 Mesh2d(meshes.add(Circle::default())),
199 MeshMaterial2d(materials.add(BALL_COLOR)),
200 Transform::from_translation(BALL_STARTING_POSITION)
201 .with_scale(Vec2::splat(BALL_DIAMETER).extend(1.)),
202 Ball,
203 Velocity(INITIAL_BALL_DIRECTION.normalize() * BALL_SPEED),
204 ));
205
206 // Scoreboard
207 commands.spawn((
208 Text::new("Score: "),
209 TextFont {
210 font_size: SCOREBOARD_FONT_SIZE,
211 ..default()
212 },
213 TextColor(TEXT_COLOR),
214 ScoreboardUi,
215 Node {
216 position_type: PositionType::Absolute,
217 top: SCOREBOARD_TEXT_PADDING,
218 left: SCOREBOARD_TEXT_PADDING,
219 ..default()
220 },
221 children![(
222 TextSpan::default(),
223 TextFont {
224 font_size: SCOREBOARD_FONT_SIZE,
225 ..default()
226 },
227 TextColor(SCORE_COLOR),
228 )],
229 ));
230
231 // Walls
232 commands.spawn(Wall::new(WallLocation::Left));
233 commands.spawn(Wall::new(WallLocation::Right));
234 commands.spawn(Wall::new(WallLocation::Bottom));
235 commands.spawn(Wall::new(WallLocation::Top));
236
237 // Bricks
238 let total_width_of_bricks = (RIGHT_WALL - LEFT_WALL) - 2. * GAP_BETWEEN_BRICKS_AND_SIDES;
239 let bottom_edge_of_bricks = paddle_y + GAP_BETWEEN_PADDLE_AND_BRICKS;
240 let total_height_of_bricks = TOP_WALL - bottom_edge_of_bricks - GAP_BETWEEN_BRICKS_AND_CEILING;
241
242 assert!(total_width_of_bricks > 0.0);
243 assert!(total_height_of_bricks > 0.0);
244
245 // Given the space available, compute how many rows and columns of bricks we can fit
246 let n_columns = (total_width_of_bricks / (BRICK_SIZE.x + GAP_BETWEEN_BRICKS)).floor() as usize;
247 let n_rows = (total_height_of_bricks / (BRICK_SIZE.y + GAP_BETWEEN_BRICKS)).floor() as usize;
248 let n_vertical_gaps = n_columns - 1;
249
250 // Because we need to round the number of columns,
251 // the space on the top and sides of the bricks only captures a lower bound, not an exact value
252 let center_of_bricks = (LEFT_WALL + RIGHT_WALL) / 2.0;
253 let left_edge_of_bricks = center_of_bricks
254 // Space taken up by the bricks
255 - (n_columns as f32 / 2.0 * BRICK_SIZE.x)
256 // Space taken up by the gaps
257 - n_vertical_gaps as f32 / 2.0 * GAP_BETWEEN_BRICKS;
258
259 // In Bevy, the `translation` of an entity describes the center point,
260 // not its bottom-left corner
261 let offset_x = left_edge_of_bricks + BRICK_SIZE.x / 2.;
262 let offset_y = bottom_edge_of_bricks + BRICK_SIZE.y / 2.;
263
264 for row in 0..n_rows {
265 for column in 0..n_columns {
266 let brick_position = Vec2::new(
267 offset_x + column as f32 * (BRICK_SIZE.x + GAP_BETWEEN_BRICKS),
268 offset_y + row as f32 * (BRICK_SIZE.y + GAP_BETWEEN_BRICKS),
269 );
270
271 // brick
272 commands.spawn((
273 Sprite {
274 color: BRICK_COLOR,
275 ..default()
276 },
277 Transform {
278 translation: brick_position.extend(0.0),
279 scale: Vec3::new(BRICK_SIZE.x, BRICK_SIZE.y, 1.0),
280 ..default()
281 },
282 Brick,
283 Collider,
284 ));
285 }
286 }
287}101fn wait_for_pending_loads(
102 loads: Populated<(Entity, &PendingLoad)>,
103 many_boxes: Res<Assets<ManyBoxes>>,
104 one_boxes: Res<Assets<OneBox>>,
105 existing_boxes: Query<Entity, With<Box>>,
106 mut commands: Commands,
107) {
108 for (entity, load) in loads.iter() {
109 let Some(many_boxes) = many_boxes.get(&load.0) else {
110 continue;
111 };
112
113 commands.entity(entity).despawn();
114 for entity in existing_boxes.iter() {
115 commands.entity(entity).despawn();
116 }
117
118 for box_handle in many_boxes.boxes.iter() {
119 let Some(one_box) = one_boxes.get(box_handle) else {
120 return;
121 };
122 commands.spawn((
123 Sprite::from_color(one_box.color, Vec2::new(100.0, 100.0)),
124 Transform::from_translation(one_box.position.extend(0.0)),
125 Pickable::default(),
126 Box,
127 ));
128 }
129 }
130}
131
132/// An asset representing a single box.
133#[derive(Asset, TypePath, Clone, Serialize, Deserialize)]
134struct OneBox {
135 /// The position of the box.
136 position: Vec2,
137 /// The color of the box.
138 color: Color,
139}
140
141/// An asset representing many boxes.
142#[derive(Asset, TypePath)]
143struct ManyBoxes {
144 /// Stores handles to all the boxes that should be spawned.
145 ///
146 /// Note: in this trivial example, it seems more reasonable to just store [`Vec<OneBox>`], but
147 /// in a more realistic example this could be something like a whole [`Mesh`] (where a handle
148 /// makes more sense). We use a handle here to demonstrate saving subassets as well.
149 boxes: Vec<Handle<OneBox>>,
150}
151
152/// A serializable version of [`ManyBoxes`].
153#[derive(Serialize, Deserialize)]
154struct SerializableManyBoxes {
155 /// The boxes that exist in this scene.
156 boxes: Vec<OneBox>,
157}
158
159/// Am asset saver to save [`ManyBoxes`] assets.
160#[derive(TypePath)]
161struct ManyBoxesSaver;
162
163impl AssetSaver for ManyBoxesSaver {
164 type Asset = ManyBoxes;
165 type Error = BevyError;
166 type OutputLoader = ManyBoxesLoader;
167 type Settings = ();
168
169 async fn save(
170 &self,
171 writer: &mut Writer,
172 asset: SavedAsset<'_, '_, Self::Asset>,
173 _settings: &Self::Settings,
174 _asset_path: AssetPath<'_>,
175 ) -> Result<(), Self::Error> {
176 let boxes = asset
177 .boxes
178 .iter()
179 .map(|handle| {
180 asset
181 .get_labeled_by_id::<OneBox>(handle)
182 .unwrap()
183 .get()
184 .clone()
185 })
186 .collect();
187
188 // Note: serializing to string isn't ideal since we can't do a streaming write, but this is
189 // fine for an example.
190 let serialized = ron::to_string(&SerializableManyBoxes { boxes })?;
191 writer.write_all(serialized.as_bytes()).await?;
192
193 Ok(())
194 }
195}
196
197/// An asset loader for loading [`ManyBoxes`] assets.
198#[derive(TypePath)]
199struct ManyBoxesLoader;
200
201impl AssetLoader for ManyBoxesLoader {
202 type Asset = ManyBoxes;
203 type Error = BevyError;
204 type Settings = ();
205
206 async fn load(
207 &self,
208 reader: &mut dyn Reader,
209 _settings: &Self::Settings,
210 load_context: &mut LoadContext<'_>,
211 ) -> Result<Self::Asset, Self::Error> {
212 let mut bytes = vec![];
213 reader.read_to_end(&mut bytes).await?;
214
215 let serialized: SerializableManyBoxes = ron::de::from_bytes(&bytes)?;
216
217 // Add the boxes as subassets.
218 let mut result_boxes = vec![];
219 for (index, one_box) in serialized.boxes.into_iter().enumerate() {
220 result_boxes.push(load_context.add_labeled_asset(index.to_string(), one_box));
221 }
222
223 Ok(ManyBoxes {
224 boxes: result_boxes,
225 })
226 }
227
228 fn extensions(&self) -> &[&str] {
229 &["boxes"]
230 }
231}
232
233/// Plugin for doing all the box-editing.
234///
235/// This doesn't really have anything to do with asset saving, but provides a real use-case.
236fn box_editing_plugin(app: &mut App) {
237 app.add_systems(Startup, setup)
238 .add_observer(spawn_box)
239 .add_observer(start_rotate_box_hue)
240 .add_observer(end_rotate_box_hue_on_release)
241 .add_observer(end_rotate_box_hue_on_out)
242 .add_systems(Update, rotate_hue)
243 .add_observer(stop_propagate_on_clicked_box)
244 .add_observer(drag_box);
245}
246
247#[derive(Component)]
248struct Box;
249
250/// Spawns the initial scene.
251fn setup(mut commands: Commands) {
252 commands.spawn(Camera2d);
253
254 commands.spawn(Text(
255 r"LMB (on background) - spawn new box
256LMB (on box) - drag to move
257RMB (on box) - rotate colors
258F5 - Save boxes
259F6 - Load boxes"
260 .into(),
261 ));
262}
263
264/// Spawns a new box whenever you left-click on the background.
265fn spawn_box(
266 press: On<PointerPress>,
267 window: Query<(), With<Window>>,
268 camera: Single<(&Camera, &GlobalTransform)>,
269 mut commands: Commands,
270) {
271 if press.button != PointerButton::Primary {
272 return;
273 }
274 if !window.contains(press.entity) {
275 return;
276 }
277
278 let (camera, camera_transform) = camera.into_inner();
279 let Ok(click_point) = camera.viewport_to_world_2d(camera_transform, press.pointer.position)
280 else {
281 return;
282 };
283 commands.spawn((
284 Sprite::from_color(tailwind::RED_500, Vec2::new(100.0, 100.0)),
285 Transform::from_translation(click_point.extend(0.0)),
286 Pickable::default(),
287 Box,
288 ));
289}26fn setup(
27 mut commands: Commands,
28 mut meshes: ResMut<Assets<Mesh>>,
29 mut materials: ResMut<Assets<ColorMaterial>>,
30 asset_server: Res<AssetServer>,
31) {
32 // Space between the two ears
33 let gap = 400.0;
34
35 // sound emitter
36 commands.spawn((
37 Mesh2d(meshes.add(Circle::new(15.0))),
38 MeshMaterial2d(materials.add(Color::from(BLUE))),
39 Transform::from_translation(Vec3::new(0.0, 50.0, 0.0)),
40 Emitter::default(),
41 AudioPlayer::new(asset_server.load("sounds/Windless Slopes.ogg")),
42 PlaybackSettings::LOOP.with_spatial(true),
43 ));
44
45 let listener = SpatialListener::new(gap);
46 commands.spawn((
47 Transform::default(),
48 Visibility::default(),
49 listener.clone(),
50 children![
51 // left ear
52 (
53 Sprite::from_color(RED, Vec2::splat(20.0)),
54 Transform::from_xyz(-gap / 2.0, 0.0, 0.0),
55 ),
56 // right ear
57 (
58 Sprite::from_color(LIME, Vec2::splat(20.0)),
59 Transform::from_xyz(gap / 2.0, 0.0, 0.0),
60 )
61 ],
62 ));
63
64 // example instructions
65 commands.spawn((
66 Text::new("Up/Down/Left/Right: Move Listener\nSpace: Toggle Emitter Movement"),
67 Node {
68 position_type: PositionType::Absolute,
69 bottom: px(12),
70 left: px(12),
71 ..default()
72 },
73 ));
74
75 // camera
76 commands.spawn(Camera2d);
77}Sourcepub fn compute_pixel_space_point(
&self,
point_relative_to_sprite: Vec2,
anchor: Anchor,
images: &Assets<Image>,
texture_atlases: &Assets<TextureAtlasLayout>,
) -> Result<Vec2, Vec2>
pub fn compute_pixel_space_point( &self, point_relative_to_sprite: Vec2, anchor: Anchor, images: &Assets<Image>, texture_atlases: &Assets<TextureAtlasLayout>, ) -> Result<Vec2, Vec2>
Computes the pixel point where point_relative_to_sprite is sampled
from in this sprite. point_relative_to_sprite must be in the sprite’s
local frame. Returns an Ok if the point is inside the bounds of the
sprite (not just the image), and returns an Err otherwise.
Examples found in repository?
208fn try_plot(
209 try_plot: On<TryPlot>,
210 sprite: Query<(&Sprite, &Anchor, &GlobalTransform), With<SpriteToSave>>,
211 camera: Single<(&Camera, &GlobalTransform)>,
212 texture_atlases: Res<Assets<TextureAtlasLayout>>,
213 draw_color: Res<DrawColor>,
214 mut images: ResMut<Assets<Image>>,
215) {
216 let Ok((sprite, anchor, sprite_transform)) = sprite.get(try_plot.entity) else {
217 return;
218 };
219 let (camera, camera_transform) = camera.into_inner();
220 let Ok(world_position) =
221 camera.viewport_to_world_2d(camera_transform, try_plot.location.position)
222 else {
223 return;
224 };
225 let relative_to_sprite = sprite_transform
226 .affine()
227 .inverse()
228 .transform_point3(world_position.extend(0.0));
229 let Ok(pixel_space) = sprite.compute_pixel_space_point(
230 relative_to_sprite.xy(),
231 *anchor,
232 &images,
233 &texture_atlases,
234 ) else {
235 return;
236 };
237 let pixel_coordinates = pixel_space.floor().as_uvec2();
238 let mut image = images.get_mut(&sprite.image).unwrap();
239 // For an actual drawing app, you'd at least draw a line from the last point, but this is
240 // simpler.
241 image
242 .set_color_at(pixel_coordinates.x, pixel_coordinates.y, draw_color.0)
243 .unwrap();
244}Trait Implementations§
Source§impl Component for Sprite
Required Components: Transform, Visibility, VisibilityClass, Anchor.
impl Component for Sprite
Required Components: Transform, Visibility, VisibilityClass, Anchor.
A component’s Required Components are inserted whenever it is inserted. Note that this will also insert the required components of the required components, recursively, in depth-first order.
Source§const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
Source§type Mutability = Mutable
type Mutability = Mutable
Component<Mutability = Mutable>,
while immutable components will instead have Component<Mutability = Immutable>. Read moreSource§fn register_required_components(
_requiree: ComponentId,
required_components: &mut RequiredComponentsRegistrator<'_, '_>,
)
fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )
Source§fn clone_behavior() -> ComponentCloneBehavior
fn clone_behavior() -> ComponentCloneBehavior
Source§fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Sprite>>
fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Sprite>>
ComponentRelationshipAccessor required for working with relationships in dynamic contexts. Read moreSource§fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
EntityMapper. This is used to remap entities in contexts like scenes and entity cloning.
When deriving Component, this is populated by annotating fields containing entities with #[entities] Read moreSource§const HAS_SUMMARY_TICK: bool = false
const HAS_SUMMARY_TICK: bool = false
Source§impl FromReflect for Sprite
impl FromReflect for Sprite
Source§fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Sprite>
fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Sprite>
Self from a reflected value.Source§fn take_from_reflect(
reflect: Box<dyn PartialReflect>,
) -> Result<Self, Box<dyn PartialReflect>>
fn take_from_reflect( reflect: Box<dyn PartialReflect>, ) -> Result<Self, Box<dyn PartialReflect>>
Self using,
constructing the value using from_reflect if that fails. Read moreSource§impl FromTemplate for Sprite
impl FromTemplate for Sprite
Source§type Template = SpriteTemplate
type Template = SpriteTemplate
Template for this type.Source§impl GetTypeRegistration for Sprite
impl GetTypeRegistration for Sprite
Source§fn get_type_registration() -> TypeRegistration
fn get_type_registration() -> TypeRegistration
TypeRegistration for this type.Source§fn register_type_dependencies(registry: &mut TypeRegistry)
fn register_type_dependencies(registry: &mut TypeRegistry)
Source§impl IntoReturn for Sprite
impl IntoReturn for Sprite
Source§impl PartialReflect for Sprite
impl PartialReflect for Sprite
Source§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
Source§fn try_apply(
&mut self,
value: &(dyn PartialReflect + 'static),
) -> Result<(), ApplyError>
fn try_apply( &mut self, value: &(dyn PartialReflect + 'static), ) -> Result<(), ApplyError>
Source§fn reflect_kind(&self) -> ReflectKind
fn reflect_kind(&self) -> ReflectKind
Source§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
Source§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
Source§fn reflect_owned(self: Box<Sprite>) -> ReflectOwned
fn reflect_owned(self: Box<Sprite>) -> ReflectOwned
Source§fn try_into_reflect(
self: Box<Sprite>,
) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
fn try_into_reflect( self: Box<Sprite>, ) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
Source§fn try_as_reflect(&self) -> Option<&(dyn Reflect + 'static)>
fn try_as_reflect(&self) -> Option<&(dyn Reflect + 'static)>
Source§fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + 'static)>
fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + 'static)>
Source§fn into_partial_reflect(self: Box<Sprite>) -> Box<dyn PartialReflect>
fn into_partial_reflect(self: Box<Sprite>) -> Box<dyn PartialReflect>
Source§fn as_partial_reflect(&self) -> &(dyn PartialReflect + 'static)
fn as_partial_reflect(&self) -> &(dyn PartialReflect + 'static)
Source§fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + 'static)
fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + 'static)
Source§fn reflect_partial_eq(
&self,
value: &(dyn PartialReflect + 'static),
) -> Option<bool>
fn reflect_partial_eq( &self, value: &(dyn PartialReflect + 'static), ) -> Option<bool>
Source§fn reflect_partial_cmp(
&self,
value: &(dyn PartialReflect + 'static),
) -> Option<Ordering>
fn reflect_partial_cmp( &self, value: &(dyn PartialReflect + 'static), ) -> Option<Ordering>
Source§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
Source§fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>
fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>
Self using reflection. Read moreSource§fn apply(&mut self, value: &(dyn PartialReflect + 'static))
fn apply(&mut self, value: &(dyn PartialReflect + 'static))
Source§fn to_dynamic(&self) -> Result<Box<dyn PartialReflect>, ReflectCloneError>
fn to_dynamic(&self) -> Result<Box<dyn PartialReflect>, ReflectCloneError>
Source§fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
PartialReflect, combines reflect_clone and
take in a useful fashion, automatically constructing an appropriate
ReflectCloneError if the downcast fails.Source§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
Source§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
Source§impl Reflect for Sprite
impl Reflect for Sprite
Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut dyn Any. Read moreSource§fn into_reflect(self: Box<Sprite>) -> Box<dyn Reflect>
fn into_reflect(self: Box<Sprite>) -> Box<dyn Reflect>
Source§fn as_reflect(&self) -> &(dyn Reflect + 'static)
fn as_reflect(&self) -> &(dyn Reflect + 'static)
Source§fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
Source§impl Struct for Sprite
impl Struct for Sprite
Source§fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>
fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>
name as a &dyn PartialReflect.Source§fn field_mut(
&mut self,
name: &str,
) -> Option<&mut (dyn PartialReflect + 'static)>
fn field_mut( &mut self, name: &str, ) -> Option<&mut (dyn PartialReflect + 'static)>
name as a
&mut dyn PartialReflect.Source§fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>
fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>
index as a
&dyn PartialReflect.Source§fn field_at_mut(
&mut self,
index: usize,
) -> Option<&mut (dyn PartialReflect + 'static)>
fn field_at_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>
index
as a &mut dyn PartialReflect.Source§fn index_of_name(&self, name: &str) -> Option<usize>
fn index_of_name(&self, name: &str) -> Option<usize>
Source§fn iter_fields(&self) -> FieldIter<'_> ⓘ
fn iter_fields(&self) -> FieldIter<'_> ⓘ
Source§fn to_dynamic_struct(&self) -> Result<DynamicStruct, ReflectCloneError>
fn to_dynamic_struct(&self) -> Result<DynamicStruct, ReflectCloneError>
DynamicStruct from this struct. Read moreSource§fn get_represented_struct_info(&self) -> Option<&'static StructInfo>
fn get_represented_struct_info(&self) -> Option<&'static StructInfo>
None if TypeInfo is not available.impl StructuralPartialEq for Sprite
Source§impl TypePath for Sprite
impl TypePath for Sprite
Source§fn type_path() -> &'static str
fn type_path() -> &'static str
Source§fn short_type_path() -> &'static str
fn short_type_path() -> &'static str
Source§fn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
Source§fn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
impl Unpin for Spritewhere
[()]: for<'a> SpecializeFromTemplate,
Auto Trait Implementations§
impl Freeze for Sprite
impl RefUnwindSafe for Sprite
impl Send for Sprite
impl Sync for Sprite
impl UnsafeUnpin for Sprite
impl UnwindSafe for Sprite
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
impl<T> Brush for T
Source§impl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut ComponentsRegistrator<'_>, ) -> impl Iterator<Item = ComponentId> + use<C>
Source§fn get_component_ids(
components: &Components,
) -> impl Iterator<Item = Option<ComponentId>>
fn get_component_ids( components: &Components, ) -> impl Iterator<Item = Option<ComponentId>>
Source§impl<C> BundleFromComponents for Cwhere
C: Component,
impl<C> BundleFromComponents for Cwhere
C: Component,
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ConditionalSend for Twhere
T: Send,
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
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
Source§unsafe fn get_components(
ptr: MovingPtr<'_, C>,
func: &mut impl FnMut(StorageType, OwningPtr<'_>),
) -> <C as DynamicBundle>::Effect
unsafe fn get_components( ptr: MovingPtr<'_, C>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect
Source§unsafe fn apply_effect(
_ptr: MovingPtr<'_, MaybeUninit<C>>,
_entity: &mut EntityWorldMut<'_>,
)
unsafe fn apply_effect( _ptr: MovingPtr<'_, MaybeUninit<C>>, _entity: &mut EntityWorldMut<'_>, )
Source§impl<T> DynamicTypePath for Twhere
T: TypePath,
impl<T> DynamicTypePath for Twhere
T: TypePath,
Source§fn reflect_type_path(&self) -> &str
fn reflect_type_path(&self) -> &str
TypePath::type_path.Source§fn reflect_short_type_path(&self) -> &str
fn reflect_short_type_path(&self) -> &str
Source§fn reflect_type_ident(&self) -> Option<&str>
fn reflect_type_ident(&self) -> Option<&str>
TypePath::type_ident.Source§fn reflect_crate_name(&self) -> Option<&str>
fn reflect_crate_name(&self) -> Option<&str>
TypePath::crate_name.Source§fn reflect_module_path(&self) -> Option<&str>
fn reflect_module_path(&self) -> Option<&str>
Source§impl<T> DynamicTyped for Twhere
T: Typed,
impl<T> DynamicTyped for Twhere
T: Typed,
Source§fn reflect_type_info(&self) -> &'static TypeInfo
fn reflect_type_info(&self) -> &'static TypeInfo
Typed::type_info.impl<T> ErasedDestructor for Twhere
T: 'static,
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<S> GetField for Swhere
S: Struct,
impl<S> GetField for Swhere
S: Struct,
Source§impl<T> GetPath for T
impl<T> GetPath for T
Source§fn reflect_path<'p>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path<'p>( &self, path: impl ReflectPath<'p>, ) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
path. Read moreSource§fn reflect_path_mut<'p>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
path. Read moreSource§fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
path. Read moreSource§fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
path. Read moreSource§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,
impl<T> HitDataExtra for T
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<G> PatchFromTemplate for Gwhere
G: FromTemplate,
impl<G> PatchFromTemplate for Gwhere
G: FromTemplate,
Source§fn patch<F>(func: F) -> TemplatePatch<F, <G as PatchFromTemplate>::Template>
fn patch<F>(func: F) -> TemplatePatch<F, <G as PatchFromTemplate>::Template>
func, and turns it into a TemplatePatch.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.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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().impl<T> Reflectable for T
Source§impl<C> SceneEffect for Cwhere
C: Component,
impl<C> SceneEffect for Cwhere
C: Component,
Source§fn apply(
self,
context: &mut TemplateContext<'_, '_>,
bundle_writer: &mut BundleWriter<'_>,
)
fn apply( self, context: &mut TemplateContext<'_, '_>, bundle_writer: &mut BundleWriter<'_>, )
impl<T> Settings for T
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.Source§impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
fn to_sample_(self) -> U
Source§impl<T> TypeData for T
impl<T> TypeData for T
Source§fn clone_type_data(&self) -> Box<dyn TypeData>
fn clone_type_data(&self) -> Box<dyn TypeData>
self.