Newer
Older
use bevy::core_pipeline::clear_color::ClearColorConfig;
use bevy::math::Vec3;
use bevy::prelude::{
App, Camera2d, Camera2dBundle, Color, Commands, OrthographicProjection, PluginGroup, Rect,
Transform, Vec2, Window, WindowPlugin,
};
use bevy::render::camera::ScalingMode;
use bevy::window::{WindowMode, WindowResolution};
use bevy::DefaultPlugins;
static VIEWPORT_WIDTH: f32 = 480.0;
static VIEWPORT_HEIGHT: f32 = 300.0;
fn spawn_camera(mut commands: Commands) {
commands.spawn(Camera2dBundle {
projection: OrthographicProjection {
area: Rect::from_center_size(Vec2::ZERO, Vec2::new(VIEWPORT_WIDTH, VIEWPORT_HEIGHT)),
scaling_mode: ScalingMode::FixedVertical(VIEWPORT_HEIGHT),
..Default::default()
},
camera_2d: Camera2d {
clear_color: ClearColorConfig::Custom(Color::WHITE),
},
transform: Transform::from_translation(Vec3::new(
VIEWPORT_WIDTH / 2.0,
VIEWPORT_HEIGHT / 2.0,
0.0,
)),
..Default::default()
});
}
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
mode: WindowMode::Windowed,
title: String::from("Shoot: The Revival"),
resizable: true,
resolution: WindowResolution::new(1280.0, 800.0),
fit_canvas_to_parent: true,
..Default::default()
}),
..Default::default()
}))
.add_startup_system(spawn_camera)
.run();