Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Separation of 2D and 3D games #510

Closed
Bauxitedev opened this issue Sep 18, 2020 · 7 comments
Closed

Separation of 2D and 3D games #510

Bauxitedev opened this issue Sep 18, 2020 · 7 comments
Labels
C-Feature A new feature, making something new possible

Comments

@Bauxitedev
Copy link

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:
image

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.

@chemicstry
Copy link

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

@Bauxitedev
Copy link
Author

@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); 

    }
}

@memoryruins
Copy link
Contributor

The sprite clipping issue has been fixed on master #385, but it has not been included in a released version yet.

@memoryruins memoryruins added the C-Feature A new feature, making something new possible label Sep 18, 2020
@Bauxitedev
Copy link
Author

@memoryruins Good to know!

@Waridley
Copy link
Contributor

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.

@alice-i-cecile
Copy link
Member

@cart I think at this point this can be closed as wontfix.

@zicklag
Copy link
Member

zicklag commented Mar 25, 2021

@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.

@bevyengine bevyengine locked and limited conversation to collaborators Jul 14, 2021
@cart cart closed this as completed Jul 14, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
C-Feature A new feature, making something new possible
Projects
None yet
Development

No branches or pull requests

7 participants