Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Add an example to draw a rectangle #2957

Closed
wants to merge 8 commits into from

Conversation

wooster0
Copy link
Contributor

Objective

Every time I come back to Bevy I face the same issue: how do I draw a rectangle again? How did that work? So I go to https://github.com/bevyengine/bevy/tree/main/examples in the hope of finding literally the simplest possible example that draws something on the screen without any dependency such as an image. I don't want to have to add some image first, I just quickly want to get something on the screen with main.rs alone so that I can continue building on from that point on. Such an example is particularly helpful for a quick start for smaller projects that don't even need any assets such as images (this is my case currently).

Currently every single example of https://github.com/bevyengine/bevy/tree/main/examples#2d-rendering (which is the first section after hello world that beginners will look for for very minimalistic and quick examples) depends on at least an asset or is too complex. This PR solves this.
It also serves as a great comparison for a beginner to realize what Bevy is really like and how different it is from what they may expect Bevy to be. For example for someone coming from LÖVE, they will have something like this in their head when they think of drawing a rectangle:

function love.draw()
    love.graphics.setColor(0.25, 0.25, 0.75);
    love.graphics.rectangle("fill", 0, 0, 50, 50);
end

This, of course, differs quite a lot from what you do in Bevy. I imagine there will be people that just want to see something as simple as this in comparison to have a better understanding for the amount of differences.

Solution

Add a dead simple example drawing a blue 50x50 rectangle in the center with no more and no less than needed.

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Oct 12, 2021
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Examples An addition or correction to our examples and removed S-Needs-Triage This issue needs to be labelled labels Oct 12, 2021
@zimzat
Copy link

zimzat commented Oct 12, 2021

This looks useful as a baseline. I'd like to see it include just a little more, such as one with an offset (this could be a way to show that zero/zero is in the middle and -30, 30 is left/top) and one with different length/width sizes.

If someone with more experience in Bevy could chime in, is it possible to draw anything other than a rectangle? Such as a circle, rounded rectangle, or triangle? With those this example could be graduated to "shapes" (mirroring the 3d_scene example) and would be very instructional for those who aren't good at drawing sprites :)

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Eventually we may want to extend this example with other shapes, but until then this is a nice simple demonstration.

@alice-i-cecile
Copy link
Member

If someone with more experience in Bevy could chime in, is it possible to draw anything other than a rectangle? Such as a circle, rounded rectangle, or triangle? With those this example could be graduated to "shapes" (mirroring the 3d_scene example) and would be very instructional for those who aren't good at drawing sprites :)

Currently, there are no other shapes supported out of the box :( bevy_prototype_lyon is the community's stopgap for now. I agree with this being a solid goal once that's in place.

@wooster0
Copy link
Contributor Author

This looks useful as a baseline. I'd like to see it include just a little more, such as one with an offset (this could be a way to show that zero/zero is in the middle and -30, 30 is left/top) and one with different length/width sizes.

I agree, such an example would be nice too. I suppose once Bevy supports more shapes out of the box another shapes.rs or other_shapes.rs in addition to rect.rs could be added to show that off as well as more shapes.

@zimzat
Copy link

zimzat commented Oct 12, 2021

Currently, there are no other shapes supported out of the box :( bevy_prototype_lyon is the community's stopgap for now. I agree with this being a solid goal once that's in place.

Ahh, thank you for that pointer @alice-i-cecile, I missed that. I've mainly been referencing the Official Examples (and Cheat Book) and started to forget about the https://bevyengine.org/assets/#2d page.

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Oct 13, 2021
@mockersf
Copy link
Member

After looking at

pub struct PipelinedSpriteBundle {
pub sprite: Sprite,
pub transform: Transform,
pub global_transform: GlobalTransform,
pub texture: Handle<Image>,
}

This may not work after the renderer rework because it won't be possible to just pick a plain color, it will be mandatory to use an image. Could someone working on the renderer confirm?

@mockersf
Copy link
Member

The new renderer has been merged, with a completely revamped SpriteBundle:

#[derive(Bundle, Clone)]
pub struct SpriteBundle {
pub sprite: Sprite,
pub transform: Transform,
pub global_transform: GlobalTransform,
pub texture: Handle<Image>,
/// User indication of whether an entity is visible
pub visibility: Visibility,
/// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering
pub computed_visibility: ComputedVisibility,
}

Could you update this PR for the new bundle?

@mockersf mockersf removed the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Dec 16, 2021
@wooster0
Copy link
Contributor Author

@mockersf I updated it hopefully correctly.

Comment on lines 13 to 16
transform: Transform {
scale: Vec3::new(50.0, 50.0, 0.0),
..Default::default()
},
Copy link
Member

@mockersf mockersf Dec 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you set the scale here? is it to replace the Sprite::new(Vec2::new(50., 50.))?

Then you could do in in the Sprite struct like

custom_size: Some(Vec2::new(1.0, 1.0) * SPRITE_SIZE),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay. That's what someone else suggested as well but neither of us were sure which one is the right way.
I tried something else now. Is it fine?

@mockersf
Copy link
Member

looking good, thanks!

@mockersf mockersf added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Dec 16, 2021
@cart
Copy link
Member

cart commented Dec 18, 2021

bors r+

bors bot pushed a commit that referenced this pull request Dec 18, 2021
# Objective

Every time I come back to Bevy I face the same issue: how do I draw a rectangle again? How did that work? So I go to https://github.com/bevyengine/bevy/tree/main/examples in the hope of finding literally the simplest possible example that draws something on the screen without any dependency such as an image. I don't want to have to add some image first, I just quickly want to get something on the screen with `main.rs` alone so that I can continue building on from that point on. Such an example is particularly helpful for a quick start for smaller projects that don't even need any assets such as images (this is my case currently).

Currently every single example of https://github.com/bevyengine/bevy/tree/main/examples#2d-rendering (which is the first section after hello world that beginners will look for for very minimalistic and quick examples) depends on at least an asset or is too complex. This PR solves this.
It also serves as a great comparison for a beginner to realize what Bevy is really like and how different it is from what they may expect Bevy to be. For example for someone coming from [LÖVE](https://love2d.org/), they will have something like this in their head when they think of drawing a rectangle:
```lua
function love.draw()
    love.graphics.setColor(0.25, 0.25, 0.75);
    love.graphics.rectangle("fill", 0, 0, 50, 50);
end
```
This, of course, differs quite a lot from what you do in Bevy. I imagine there will be people that just want to see something as simple as this in comparison to have a better understanding for the amount of differences.

## Solution

Add a dead simple example drawing a blue 50x50 rectangle in the center with no more and no less than needed.
@bors bors bot changed the title Add an example to draw a rectangle [Merged by Bors] - Add an example to draw a rectangle Dec 18, 2021
@bors bors bot closed this Dec 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Examples An addition or correction to our examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants