mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Some examples of documentation (#338)
This commit is contained in:
parent
7b4bdef77c
commit
0ae74a4a4d
3 changed files with 24 additions and 2 deletions
|
@ -240,7 +240,9 @@ impl<'a, T: Component> Fetch<'a> for FetchMut<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
/// Query transformer that skips entities that have a `T` component that has
|
||||
/// not been mutated since the last pass of the system. This does not include
|
||||
/// components that were added in since the last pass.
|
||||
pub struct Mutated<'a, T> {
|
||||
value: &'a T,
|
||||
}
|
||||
|
@ -368,7 +370,8 @@ impl<'a, T: Component> Fetch<'a> for FetchAdded<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
/// Query transformer skipping entities that have not been either mutated or added
|
||||
/// since the last pass of the system
|
||||
pub struct Changed<'a, T> {
|
||||
value: &'a T,
|
||||
}
|
||||
|
|
|
@ -63,10 +63,15 @@ impl Default for SpriteComponents {
|
|||
}
|
||||
}
|
||||
|
||||
/// A Bundle of components for drawing a single sprite from a sprite sheet (also referred
|
||||
/// to as a `TextureAtlas`)
|
||||
#[derive(Bundle)]
|
||||
pub struct SpriteSheetComponents {
|
||||
/// The specific sprite from the texture atlas to be drawn
|
||||
pub sprite: TextureAtlasSprite,
|
||||
/// A handle to the texture atlas that holds the sprite images
|
||||
pub texture_atlas: Handle<TextureAtlas>,
|
||||
/// Data pertaining to how the sprite is drawn on the screen
|
||||
pub draw: Draw,
|
||||
pub render_pipelines: RenderPipelines,
|
||||
pub main_pass: MainPass,
|
||||
|
|
|
@ -9,11 +9,14 @@ use bevy_render::{
|
|||
};
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// An atlas containing multiple textures (like a spritesheet or a tilemap)
|
||||
#[derive(RenderResources)]
|
||||
pub struct TextureAtlas {
|
||||
/// The handle to the texture in which the sprites are stored
|
||||
pub texture: Handle<Texture>,
|
||||
// TODO: add support to Uniforms derive to write dimensions and sprites to the same buffer
|
||||
pub size: Vec2,
|
||||
/// The specific areas of the atlas where each texture can be found
|
||||
#[render_resources(buffer)]
|
||||
pub textures: Vec<Rect>,
|
||||
#[render_resources(ignore)]
|
||||
|
@ -48,6 +51,8 @@ impl TextureAtlasSprite {
|
|||
}
|
||||
|
||||
impl TextureAtlas {
|
||||
/// Create a new `TextureAtlas` that has a texture, but does not have
|
||||
/// any individual sprites specified
|
||||
pub fn new_empty(texture: Handle<Texture>, dimensions: Vec2) -> Self {
|
||||
Self {
|
||||
texture,
|
||||
|
@ -57,6 +62,8 @@ impl TextureAtlas {
|
|||
}
|
||||
}
|
||||
|
||||
/// Generate a `TextureAtlas` by splitting a texture into a grid where each
|
||||
/// cell of the grid is one of the textures in the atlas
|
||||
pub fn from_grid(
|
||||
texture: Handle<Texture>,
|
||||
size: Vec2,
|
||||
|
@ -85,10 +92,17 @@ impl TextureAtlas {
|
|||
}
|
||||
}
|
||||
|
||||
/// Add a sprite to the list of textures in the `TextureAtlas`
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `rect` - The section of the atlas that contains the texture to be added,
|
||||
/// from the top-left corner of the texture to the bottom-right corner
|
||||
pub fn add_texture(&mut self, rect: Rect) {
|
||||
self.textures.push(rect);
|
||||
}
|
||||
|
||||
/// How many textures are in the `TextureAtlas`
|
||||
pub fn len(&self) -> usize {
|
||||
self.textures.len()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue