Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/bevy_sprite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ bevy_transform = { path = "../bevy_transform", version = "0.18.0-dev" }
bevy_window = { path = "../bevy_window", version = "0.18.0-dev", optional = true }
bevy_derive = { path = "../bevy_derive", version = "0.18.0-dev" }
bevy_text = { path = "../bevy_text", version = "0.18.0-dev", optional = true }
bevy_log = { path = "../bevy_log", version = "0.18.0-dev" }

# other
radsort = "0.1"
Expand Down
21 changes: 16 additions & 5 deletions crates/bevy_sprite/src/picking_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use bevy_camera::{
};
use bevy_color::Alpha;
use bevy_ecs::prelude::*;
use bevy_image::prelude::*;
use bevy_image::{prelude::*, TextureAccessError};
use bevy_log::warn;
use bevy_math::{prelude::*, FloatExt};
use bevy_picking::backend::prelude::*;
use bevy_reflect::prelude::*;
Expand Down Expand Up @@ -243,12 +244,22 @@ fn sprite_picking(
break 'valid_pixel true;
};
// grab pixel and check alpha
let Ok(color) = image.get_color_at(
let color = match image.get_color_at(
cursor_pixel_space.x as u32,
cursor_pixel_space.y as u32,
) else {
// We don't know how to interpret the pixel.
break 'valid_pixel false;
) {
Ok(color) => color,
Err(TextureAccessError::UnsupportedTextureFormat(format)) => {
warn!(
"Failed to get pixel color for sprite picking on entity {:?}: unsupported texture format {:?}. \
This is often caused by the use of a compressed texture format. \
Consider using `SpritePickingMode::BoundingBox`.",
entity,
format
);
break 'valid_pixel false;
}
Err(_) => break 'valid_pixel false,
};
// Check the alpha is above the cutoff.
color.alpha() > cutoff
Expand Down
Loading