# Objective Yet another PR for migrating stuff to required components. This time, cameras! ## Solution As per the [selected proposal](https://hackmd.io/tsYID4CGRiWxzsgawzxG_g#Combined-Proposal-1-Selected), deprecate `Camera2dBundle` and `Camera3dBundle` in favor of `Camera2d` and `Camera3d`. Adding a `Camera` without `Camera2d` or `Camera3d` now logs a warning, as suggested by Cart [on Discord](https://discord.com/channels/691052431525675048/1264881140007702558/1291506402832945273). I would personally like cameras to work a bit differently and be split into a few more components, to avoid some footguns and confusing semantics, but that is more controversial, and shouldn't block this core migration. ## Testing I ran a few 2D and 3D examples, and tried cameras with and without render graphs. --- ## Migration Guide `Camera2dBundle` and `Camera3dBundle` have been deprecated in favor of `Camera2d` and `Camera3d`. Inserting them will now also insert the other components required by them automatically.
		
			
				
	
	
		
			82 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			82 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
//! Demonstrates how to use transparency with UI.
 | 
						|
//! Shows two colored buttons with transparent text.
 | 
						|
 | 
						|
use bevy::prelude::*;
 | 
						|
 | 
						|
fn main() {
 | 
						|
    App::new()
 | 
						|
        .insert_resource(ClearColor(Color::BLACK))
 | 
						|
        .add_plugins(DefaultPlugins)
 | 
						|
        .add_systems(Startup, setup)
 | 
						|
        .run();
 | 
						|
}
 | 
						|
 | 
						|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
 | 
						|
    commands.spawn(Camera2d);
 | 
						|
 | 
						|
    let font_handle = asset_server.load("fonts/FiraSans-Bold.ttf");
 | 
						|
 | 
						|
    commands
 | 
						|
        .spawn(NodeBundle {
 | 
						|
            style: Style {
 | 
						|
                width: Val::Percent(100.0),
 | 
						|
                height: Val::Percent(100.0),
 | 
						|
                align_items: AlignItems::Center,
 | 
						|
                justify_content: JustifyContent::SpaceAround,
 | 
						|
                ..default()
 | 
						|
            },
 | 
						|
            ..default()
 | 
						|
        })
 | 
						|
        .with_children(|parent| {
 | 
						|
            parent
 | 
						|
                .spawn(ButtonBundle {
 | 
						|
                    style: Style {
 | 
						|
                        width: Val::Px(150.0),
 | 
						|
                        height: Val::Px(65.0),
 | 
						|
                        justify_content: JustifyContent::Center,
 | 
						|
                        align_items: AlignItems::Center,
 | 
						|
                        ..default()
 | 
						|
                    },
 | 
						|
                    background_color: Color::srgb(0.1, 0.5, 0.1).into(),
 | 
						|
                    ..default()
 | 
						|
                })
 | 
						|
                .with_children(|parent| {
 | 
						|
                    parent.spawn(TextBundle::from_section(
 | 
						|
                        "Button 1",
 | 
						|
                        TextStyle {
 | 
						|
                            font: font_handle.clone(),
 | 
						|
                            font_size: 33.0,
 | 
						|
                            // Alpha channel of the color controls transparency.
 | 
						|
                            color: Color::srgba(1.0, 1.0, 1.0, 0.2),
 | 
						|
                        },
 | 
						|
                    ));
 | 
						|
                });
 | 
						|
 | 
						|
            // Button with a different color,
 | 
						|
            // to demonstrate the text looks different due to its transparency.
 | 
						|
            parent
 | 
						|
                .spawn(ButtonBundle {
 | 
						|
                    style: Style {
 | 
						|
                        width: Val::Px(150.0),
 | 
						|
                        height: Val::Px(65.0),
 | 
						|
                        justify_content: JustifyContent::Center,
 | 
						|
                        align_items: AlignItems::Center,
 | 
						|
                        ..default()
 | 
						|
                    },
 | 
						|
                    background_color: Color::srgb(0.5, 0.1, 0.5).into(),
 | 
						|
                    ..default()
 | 
						|
                })
 | 
						|
                .with_children(|parent| {
 | 
						|
                    parent.spawn(TextBundle::from_section(
 | 
						|
                        "Button 2",
 | 
						|
                        TextStyle {
 | 
						|
                            font: font_handle.clone(),
 | 
						|
                            font_size: 33.0,
 | 
						|
                            // Alpha channel of the color controls transparency.
 | 
						|
                            color: Color::srgba(1.0, 1.0, 1.0, 0.2),
 | 
						|
                        },
 | 
						|
                    ));
 | 
						|
                });
 | 
						|
        });
 | 
						|
}
 |