Skip to content
Snippets Groups Projects
Verified Commit 00ba6b7d authored by Louis's avatar Louis :fire:
Browse files

Set up camera & viewport

parent 76c8d543
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
......@@ -6,3 +6,20 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
log = "0.4.19"
[dependencies.bevy]
version = "0.10.1"
default-features = false
features = [
"bevy_asset",
"bevy_sprite",
"bevy_winit",
"png",
"hdr",
"x11",
"wayland",
"serialize",
"filesystem_watcher",
"bevy_core_pipeline",
]
hard_tabs = true
use_field_init_shorthand = true
use_try_shorthand = true
\ No newline at end of file
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()
});
}
fn main() {
println!("Hello, world!");
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();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment