-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Support texture atlases in CustomCursor::Image #17121
base: main
Are you sure you want to change the base?
Conversation
Another showcase video. This is a more realistic in-game animated cursor. The pointer animates every 5s (blink and you'll miss it): Screen.Recording.2025-01-03.at.11.15.03.PM.mov |
First off: Thank you for attributing to Kenney. He's a cool person. :D Second off: I don't see any assets added by this PR? All the files touched are code, except for |
c6ba500
to
2f77a85
Compare
@eero-lehtinen 👋 would you be interested in reviewing this PR for texture atlas support on custom cursor images? |
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.
Seems fine to me except for a couple of things.
crates/bevy_winit/src/cursor.rs
Outdated
_ => None, | ||
}; | ||
|
||
let image_data = image_data?; |
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.
I would like to keep a fast path when there is no transformations and just return the data.
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.
Makes sense, I think I can adjust this.
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.
Done. There are technically some cases where texture atlas might be the full image rect, but I decided to not let those follow the fast path since it's not obvious to me how to check that properly.
# Objective - Allow other crates to use `TextureAtlas` and friends without needing to depend on `bevy_sprite`. - Specifically, this allows adding `TextureAtlas` support to custom cursors in #17121 by allowing `bevy_winit` to depend on `bevy_image` instead of `bevy_sprite` which is a [non-starter]. [non-starter]: #17121 (comment) ## Solution - Move `TextureAtlas`, `TextureAtlasBuilder`, `TextureAtlasSources`, `TextureAtlasLayout` and `DynamicTextureAtlasBuilder` into `bevy_image`. - Add a new plugin to `bevy_image` named `TextureAtlasPlugin` which allows us to register `TextureAtlas` and `TextureAtlasLayout` which was previously done in `SpritePlugin`. Since `SpritePlugin` did the registration previously, we just need to make it add `TextureAtlasPlugin`. ## Testing - CI builds it. - I also ran multiple examples which hopefully covered any issues: ``` $ cargo run --example sprite $ cargo run --example text $ cargo run --example ui_texture_atlas $ cargo run --example sprite_animation $ cargo run --example sprite_sheet $ cargo run --example sprite_picking ``` --- ## Migration Guide The following types have been moved from `bevy_sprite` to `bevy_image`: `TextureAtlas`, `TextureAtlasBuilder`, `TextureAtlasSources`, `TextureAtlasLayout` and `DynamicTextureAtlasBuilder`. If you are using the `bevy` crate, and were importing these types directly (e.g. before `use bevy::sprite::TextureAtlas`), be sure to update your import paths (e.g. after `use bevy::image::TextureAtlas`) If you are using the `bevy` prelude to import these types (e.g. `use bevy::prelude::*`), you don't need to change anything. If you are using the `bevy_sprite` subcrate, be sure to add `bevy_image` as a dependency if you do not already have it, and be sure to update your import paths.
00a36d4
to
569260c
Compare
Changes (also see latest commits):
|
I don't have time to do a full code review, but I'll run the examples when I get to my laptop |
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.
custom_cursor_image works. window_settings actually seems broken here and on main.
@BenjaminBrienen how so? Seems to work for me. You need to left/right click to cycle the cursor icon if you didn't already do that. |
See #17227 |
Objective
Handle<Image>
: You can't use aTextureAtlas
like you can with sprites and UI images.Image
assets, but that seems less than ideal.Solution
TextureAtlas
field when creating a custom cursor image.TextureAtlas
support onSprite
s andImageNode
s, this also allows users to specifyrect
,flip_x
andflip_y
. In fact, for my own use case, I need toflip_y
.Testing
calculate_effective_rect
andextract_and_transform_rgba_pixels
.window_settings
) would be far too messy for showcasing these custom cursor features (I did start down that path but decided to stop and make a brand new example).Showcase
custom-cursor-001.mov
Migration Guide
The
CustomCursor::Image
enum variant has some new fields. Update your code to set them.Before:
After:
References