Add docs to bevy_sprite a little (#10947)

# Objective

- bevy_sprite crate is missing docs for important types. `Sprite` being
undocumented was especially confusing for me even though it is one of
the first types I need to learn.
 
## Solution

- Improves the situation a little by adding some documentations.
I'm unsure about my understanding of functionality and writing. I'm
happy to be pointed out any mistakes.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Federico Rinaldi <gisquerin@gmail.com>
This commit is contained in:
akimakinai 2023-12-15 02:25:55 +09:00 committed by GitHub
parent 381277d6c3
commit 83fbf48238
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 2 deletions

View File

@ -10,11 +10,16 @@ use bevy_render::{
}; };
use bevy_transform::components::{GlobalTransform, Transform}; use bevy_transform::components::{GlobalTransform, Transform};
/// A [`Bundle`] of components for drawing a single sprite from an image.
#[derive(Bundle, Clone, Default)] #[derive(Bundle, Clone, Default)]
pub struct SpriteBundle { pub struct SpriteBundle {
/// Specifies the rendering properties of the sprite, such as color tint and flip.
pub sprite: Sprite, pub sprite: Sprite,
/// The local transform of the sprite, relative to its parent.
pub transform: Transform, pub transform: Transform,
/// The absolute transform of the sprite. This should generally not be written to directly.
pub global_transform: GlobalTransform, pub global_transform: GlobalTransform,
/// A reference-counted handle to the image asset to be drawn.
pub texture: Handle<Image>, pub texture: Handle<Image>,
/// User indication of whether an entity is visible /// User indication of whether an entity is visible
pub visibility: Visibility, pub visibility: Visibility,
@ -24,8 +29,8 @@ pub struct SpriteBundle {
pub view_visibility: ViewVisibility, pub view_visibility: ViewVisibility,
} }
/// A Bundle of components for drawing a single sprite from a sprite sheet (also referred /// A [`Bundle`] of components for drawing a single sprite from a sprite sheet (also referred
/// to as a `TextureAtlas`) /// to as a `TextureAtlas`).
#[derive(Bundle, Clone, Default)] #[derive(Bundle, Clone, Default)]
pub struct SpriteSheetBundle { pub struct SpriteSheetBundle {
/// The specific sprite from the texture atlas to be drawn, defaulting to the sprite at index 0. /// The specific sprite from the texture atlas to be drawn, defaulting to the sprite at index 0.

View File

@ -2,6 +2,7 @@
use bevy_math::{Vec2, Vec3}; use bevy_math::{Vec2, Vec3};
/// The side where a collision occurred, as returned by [`collide`].
#[derive(Debug, PartialEq, Eq, Copy, Clone)] #[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum Collision { pub enum Collision {
Left, Left,

View File

@ -1,3 +1,4 @@
//! Provides 2D sprite rendering functionality.
mod bundle; mod bundle;
mod dynamic_texture_atlas_builder; mod dynamic_texture_atlas_builder;
mod mesh2d; mod mesh2d;
@ -40,11 +41,13 @@ use bevy_render::{
ExtractSchedule, Render, RenderApp, RenderSet, ExtractSchedule, Render, RenderApp, RenderSet,
}; };
/// Adds support for 2D sprite rendering.
#[derive(Default)] #[derive(Default)]
pub struct SpritePlugin; pub struct SpritePlugin;
pub const SPRITE_SHADER_HANDLE: Handle<Shader> = Handle::weak_from_u128(2763343953151597127); pub const SPRITE_SHADER_HANDLE: Handle<Shader> = Handle::weak_from_u128(2763343953151597127);
/// System set for sprite rendering.
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)] #[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
pub enum SpriteSystem { pub enum SpriteSystem {
ExtractSprites, ExtractSprites,

View File

@ -756,6 +756,7 @@ pub fn prepare_sprites(
} }
} }
/// [`RenderCommand`] for sprite rendering.
pub type DrawSprite = ( pub type DrawSprite = (
SetItemPipeline, SetItemPipeline,
SetSpriteViewBindGroup<0>, SetSpriteViewBindGroup<0>,

View File

@ -3,6 +3,9 @@ use bevy_math::{Rect, Vec2};
use bevy_reflect::{std_traits::ReflectDefault, Reflect}; use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::color::Color; use bevy_render::color::Color;
/// Specifies the rendering properties of a sprite.
///
/// This is commonly used as a component within [`SpriteBundle`](crate::bundle::SpriteBundle).
#[derive(Component, Debug, Default, Clone, Reflect)] #[derive(Component, Debug, Default, Clone, Reflect)]
#[reflect(Component, Default)] #[reflect(Component, Default)]
#[repr(C)] #[repr(C)]

View File

@ -22,6 +22,9 @@ pub struct TextureAtlas {
pub(crate) texture_handles: Option<HashMap<AssetId<Image>, usize>>, pub(crate) texture_handles: Option<HashMap<AssetId<Image>, usize>>,
} }
/// Specifies the rendering properties of a sprite from a sprite sheet.
///
/// This is commonly used as a component within [`SpriteSheetBundle`](crate::bundle::SpriteSheetBundle).
#[derive(Component, Debug, Clone, Reflect)] #[derive(Component, Debug, Clone, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct TextureAtlasSprite { pub struct TextureAtlasSprite {