Closed Bauxitedev closed 3 years ago
You are probably getting these artifacts because you did not set is_transparent: true
in Draw
component. Z component in 2D rendering does make sense as it defines draw ordering.
There definitely is some overhead from 3D transforms, but I don't think this can cause any problems unless your game goes to extreme entity numbers. The burden of maintaining separate 2D code is not worth the questionable performance gain. Maybe someone can give a different opinion
@chemicstry I am using the is_transparent
option already.
Here's the system I am using to spawn the sprites:
fn setup_system(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<ColorMaterial>>,
mut textures: ResMut<Assets<Texture>>
) {
let icon_ids: Vec<_> = asset_server
.load_asset_folder("assets/textures")
.unwrap();
commands
.spawn(Camera2dComponents::default());
let paths = fs::read_dir("assets/textures").unwrap();
let mut x = -600.0;
for path in paths {
x += 64.0;
let path = path.unwrap().path();
println!("Name: {}", path.display());
let texture_handle = asset_server.get_handle(path).unwrap();
let sprite_bundle = SpriteComponents {
translation: Translation::new(x, x * 0.2, 0.0),
material: materials.add(ColorMaterial {
color: Color::rgba(1.0, 1.0, 1.0, 0.5),
texture: texture_handle.into()
}),
draw: Draw {
is_transparent: true,
..Default::default()
},
..Default::default()
};
commands
.spawn(sprite_bundle).with(Icon);
}
}
The sprite clipping issue has been fixed on master https://github.com/bevyengine/bevy/pull/385, but it has not been included in a released version yet.
@memoryruins Good to know!
FWIW, Godot is actually unusual in having a dedicated 2D engine in addition to 3D. It's one of its unique features they tout as an advantage over competitors. However, many if not most 3D game engines "fake" 2D this way. It has some advantages, even in terms of ease of use for some situations. Some people even argue that it's better than working with pixels anyway.
However, I believe the way 2D works in Godot was actually born out of the UI system first if I'm not mistaken, and Cart does want to model Bevy's UI after Godot's (making the editor a "game" built out of the UI components in the engine.) So it may make sense for Bevy to implement 2D in a similar way to Godot -- it's worth discussing IMO.
@cart I think at this point this can be closed as wontfix
.
@Bauxitedev While it is still just work-in-progress, you may be interested in the new Bevy Retro plugin which does 2D similarly to Godot does with a focus on pixel-perfect rendering.
I'm not sure if I'm doing anything wrong, but it appears Bevy mixes 2D and 3D games together. The engine appears to be always running in 3D, but if you use a Camera2DComponent, the camera simply switches to a orthographic side view... but 3D features, like the depth buffer, are still enabled. This results in weird artifacts like this, where sprites with an alpha channel cut each other off when drawn in an overlapping way:
Additionally, components like SpriteComponents take a 3D translation vector, even though the z component does not make sense in a 2D game.
I think it would be better if it worked more like Godot, where 2D and 3D are two completely separate worlds. 2D entities also have their own 2D-specific nodes. This makes it much easier to make pixel-perfect games, since the pixels are mapped 1:1 from the world to the screen.