Skip to content

Commit

Permalink
Some examples of documentation (bevyengine#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavientois authored Aug 25, 2020
1 parent 7b4bdef commit 0ae74a4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crates/bevy_ecs/hecs/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_sprite/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions crates/bevy_sprite/src/texture_atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit 0ae74a4

Please sign in to comment.