Skip to content

Commit

Permalink
fixed story background image scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Ipagaxi committed Jul 14, 2023
1 parent c7c5446 commit d821587
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
8 changes: 0 additions & 8 deletions pc/assets/level/008.tmx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@
<property name="story">[[pre_level]]

text = &quot;&quot;&quot;

Haven't we seen something similar to this before? Hmm…

Programmers, let's use this place to practice a bit again.

But I give you one small restraint.

You may not use your trusty &quot;Motor Off&quot; and &quot;Motor On&quot; Cards here.

Good luck!

&quot;&quot;&quot;

profil = &quot;Captain&quot;
Expand All @@ -27,10 +21,8 @@ profil = &quot;Captain&quot;
[[after_level]]

text = &quot;&quot;&quot;

One more tricky situation is done.
You all really are getting good at this.

&quot;&quot;&quot;

profil = &quot;Captain&quot;</property>
Expand Down
14 changes: 10 additions & 4 deletions pc/src/story_display.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{assets::GetTexture, GameState};
use macroquad::{
math::Vec2,
prelude::{draw_rectangle, screen_height, screen_width, Color, WHITE},
prelude::{draw_rectangle, screen_height, screen_width, vec2, Color, WHITE},
text::{draw_text_ex, measure_text, TextParams},
texture::{draw_texture_ex, DrawTextureParams},
window::next_frame
Expand Down Expand Up @@ -50,13 +50,20 @@ impl GameState {
let screen_height = screen_height();
if let Some(background) = &speech.background {
let background_texture = background.texture();
let relative_size = (screen_width
/ background_texture.width())
.max(screen_height / background_texture.height());
let background_dim = vec2(
relative_size * background_texture.width(),
relative_size * background_texture.height()
);
let draw_params = DrawTextureParams {
dest_size: Some(Vec2::new(screen_width, screen_height)),
dest_size: Some(background_dim),
..Default::default()
};
draw_texture_ex(
background_texture,
0.0,
-(background_dim.x - screen_width),
0.0,
WHITE,
draw_params
Expand Down Expand Up @@ -104,7 +111,6 @@ impl GameState {
text_box_height
);
for (x, line) in group.iter().enumerate() {
//let text_dim = measure_text(line, None, font_size, 1.0);
let max_text_dim =
measure_text(&speech.text, None, font_size, 1.0);
let text_params = TextParams {
Expand Down

0 comments on commit d821587

Please sign in to comment.