Skip to content

Commit

Permalink
fix: Prevent game from fitting to parent to stop window growing
Browse files Browse the repository at this point in the history
  • Loading branch information
PraxTube committed Jul 19, 2024
1 parent 11de736 commit 259bd65
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 20 deletions.
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub use assets::GameAssets;

use bevy::asset::AssetMetaCheck;
use bevy::prelude::*;
use bevy::window::{PresentMode, Window, WindowMode};
use bevy::window::{PresentMode, Window, WindowMode, WindowResolution};

use bevy_asset_loader::prelude::*;
use bevy_rapier2d::prelude::*;
Expand Down Expand Up @@ -44,7 +44,9 @@ fn main() {
primary_window: Some(Window {
present_mode: PresentMode::Fifo,
mode: WindowMode::Windowed,
fit_canvas_to_parent: true,
fit_canvas_to_parent: false,
canvas: Some("#game-canvas".to_string()),
resolution: WindowResolution::new(1280.0, 720.0),
..default()
}),
..default()
Expand Down
5 changes: 1 addition & 4 deletions src/ui/pop_up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ impl Plugin for PopUpPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
Update,
(
spawn_pop_ups.run_if(in_state(GameState::Gaming)),
despawn_pop_ups,
),
(spawn_pop_ups, despawn_pop_ups).run_if(in_state(GameState::Gaming)),
);
}
}
3 changes: 1 addition & 2 deletions src/world/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::player::Player;
#[cfg(not(target_arch = "wasm32"))]
use crate::player::PlayerState;
use crate::spell::debug_spell::DebugSpell;
use crate::GameState;

// How much `1.0` in bevy coordinates translates to the pixels of a sprite.
// Only relevant for the ysorting.
Expand Down Expand Up @@ -129,7 +128,7 @@ impl Plugin for CameraPlugin {
zoom_camera,
),
)
.add_systems(OnEnter(GameState::Gaming), spawn_camera)
.add_systems(Startup, spawn_camera)
.add_systems(
PostUpdate,
update_camera_target
Expand Down
13 changes: 1 addition & 12 deletions wasm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@

<body>
<div class="game-container">
<div id="canvas-container"></div>
<div id="game-canvas"></div>
<div id="loading">
<span class="loader"></span>
</div>
</div>

<script type="module">
console.log("initiating bevy game");
import './restart-audio-context.js'
import init from './bevy_game.js'

Expand All @@ -27,23 +26,13 @@

console.log("loaded bevy game now");

// Function to move canvas to the specified container
function moveCanvas() {
const canvas = document.querySelector('canvas');
const canvasContainer = document.getElementById('canvas-container');
if (canvas && canvasContainer) {
canvasContainer.appendChild(canvas);
}
}

// Hide loading screen and move canvas when the game starts
const loading = document.getElementById('loading');
const observer = new MutationObserver(() => {
console.log("checkign for canvas");
const canvas = document.querySelector('canvas');
if (canvas) {
loading.style.display = 'none';
moveCanvas();
observer.disconnect();
} else {
console.warn("no canvas item");
Expand Down

0 comments on commit 259bd65

Please sign in to comment.