-
This seems like it should be easy but I haven't found a straight answer on how to do this anywhere. So I spawn new ...
commands. Spawn((
SpriteBundle {
transform: Transform::from_xyz(x, y, 0.0).with_scale(Vec3::splat(0.1)),
texture: asset_server.load("images/S.png"),
..default()
},
...
));
... I found this example of reading an images dimensions fn confine(
mut confinable_query: Query<(&mut Transform, &Handle<Image>), With<Confinable>>,
assets: Res<Assets<Image>>
) {
let window = window_query.get_single().unwrap();
for (mut transform, image_handle) in confinable_query.iter_mut() {
let image_dimensions = assets.get(image_handle).unwrap().size();
... but it seems the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
from but the gist is you can pull the scaling factor from the transform. fn print_sprite_bounding_boxes(
mut sprite_query: Query<(&Transform, &Handle<Image>), With<Sprite>>,
assets: Res<Assets<Image>>,
) {
for (transform, image_handle) in sprite_query.iter_mut() {
let image_dimensions = assets.get(image_handle).unwrap().size();
let scaled_image_dimension = image_dimensions * transform.scale.truncate();
let bounding_box = Rect::from_center_size(transform.translation.truncate(), scaled_image_dimension);
println!("bounding_box: {:?}", bounding_box);
}
} I guess Reddit wins between Stack Overflow and here. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
from but the gist is you can pull the scaling factor from the transform.
I guess Reddit wins between Stack Overflow and here.