-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
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 |
There was a problem hiding this 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.
Currently, there are no other shapes supported out of the box :( |
I agree, such an example would be nice too. I suppose once Bevy supports more shapes out of the box another |
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. |
After looking at bevy/pipelined/bevy_sprite2/src/bundle.rs Lines 11 to 16 in 43e8a15
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? |
The new renderer has been merged, with a completely revamped bevy/crates/bevy_sprite/src/bundle.rs Lines 13 to 23 in 49a4009
Could you update this PR for the new bundle? |
@mockersf I updated it hopefully correctly. |
examples/2d/rect.rs
Outdated
transform: Transform { | ||
scale: Vec3::new(50.0, 50.0, 0.0), | ||
..Default::default() | ||
}, |
There was a problem hiding this comment.
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
bevy/examples/2d/contributors.rs
Line 100 in 7356f15
custom_size: Some(Vec2::new(1.0, 1.0) * SPRITE_SIZE), |
There was a problem hiding this comment.
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?
looking good, thanks! |
bors r+ |
# 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.
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:
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.