mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 15:14:50 +00:00
89217171b4
OK, here's my attempt at sprite flipping. There are a couple of points that I need review/help on, but I think the UX is about ideal: ```rust .spawn(SpriteBundle { material: materials.add(texture_handle.into()), sprite: Sprite { // Flip the sprite along the x axis flip: SpriteFlip { x: true, y: false }, ..Default::default() }, ..Default::default() }); ``` Now for the issues. The big issue is that for some reason, when flipping the UVs on the sprite, there is a light "bleeding" or whatever you call it where the UV tries to sample past the texture boundry and ends up clipping. This is only noticed when resizing the window, though. You can see a screenshot below. ![image](https://user-images.githubusercontent.com/25393315/107098172-397aaa00-67d4-11eb-8e02-c90c820cd70e.png) I am quite baffled why the texture sampling is overrunning like it is and could use some guidance if anybody knows what might be wrong. The other issue, which I just worked around, is that I had to remove the `#[render_resources(from_self)]` annotation from the Spritesheet because the `SpriteFlip` render resource wasn't being picked up properly in the shader when using it. I'm not sure what the cause of that was, but by removing the annotation and re-organizing the shader inputs accordingly the problem was fixed. I'm not sure if this is the most efficient way to do this or if there is a better way, but I wanted to try it out if only for the learning experience. Let me know what you think!
29 lines
799 B
Rust
29 lines
799 B
Rust
use bevy::prelude::*;
|
|
|
|
fn main() {
|
|
App::build()
|
|
.add_plugins(DefaultPlugins)
|
|
.add_startup_system(setup.system())
|
|
.run();
|
|
}
|
|
|
|
fn setup(
|
|
commands: &mut Commands,
|
|
asset_server: Res<AssetServer>,
|
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
|
) {
|
|
let texture_handle = asset_server.load("branding/icon.png");
|
|
commands
|
|
.spawn(OrthographicCameraBundle::new_2d())
|
|
.spawn(SpriteBundle {
|
|
material: materials.add(texture_handle.into()),
|
|
sprite: Sprite {
|
|
// Flip the logo to the left
|
|
flip_x: true,
|
|
// And don't flip it upside-down ( the default )
|
|
flip_y: false,
|
|
..Default::default()
|
|
},
|
|
..Default::default()
|
|
});
|
|
}
|