Skip to content

Commit

Permalink
fix texture bleeding and object jittering
Browse files Browse the repository at this point in the history
  • Loading branch information
Alula committed Nov 25, 2020
1 parent f5c813a commit cf5ee5b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/shared_game_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::sound::SoundManager;
use crate::stage::StageData;
use crate::str;
use crate::text_script::{ScriptMode, TextScriptExecutionState, TextScriptVM};
use crate::texture_set::TextureSet;
use crate::texture_set::{TextureSet, g_mag};
use crate::touch_controls::TouchControls;

#[derive(PartialEq, Eq, Copy, Clone)]
Expand Down Expand Up @@ -169,6 +169,8 @@ impl SharedGameState {
pub fn new(ctx: &mut Context) -> GameResult<SharedGameState> {
let screen_size = graphics::drawable_size(ctx);
let scale = screen_size.1.div(235.0).floor().max(1.0);
unsafe { g_mag = scale };

let canvas_size = (screen_size.0 / scale, screen_size.1 / scale);

let mut constants = EngineConstants::defaults();
Expand Down Expand Up @@ -344,6 +346,7 @@ impl SharedGameState {
self.screen_size = graphics::drawable_size(ctx);
self.scale = self.screen_size.1.div(240.0).floor().max(1.0);
self.canvas_size = (self.screen_size.0 / self.scale, self.screen_size.1 / self.scale);
unsafe { g_mag = self.scale };

graphics::set_screen_coordinates(ctx, graphics::Rect::new(0.0, 0.0, self.screen_size.0, self.screen_size.1))?;

Expand Down
9 changes: 8 additions & 1 deletion src/texture_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use crate::engine_constants::EngineConstants;
use crate::shared_game_state::{Season, Settings};
use crate::str;

pub static mut g_mag: f32 = 1.0;

pub struct SizedBatch {
pub batch: SpriteBatch,
width: usize,
Expand Down Expand Up @@ -76,11 +78,16 @@ impl SizedBatch {
self.add_rect_scaled(x, y, self.scale_x, self.scale_y, rect)
}

pub fn add_rect_scaled(&mut self, x: f32, y: f32, scale_x: f32, scale_y: f32, rect: &common::Rect<u16>) {
pub fn add_rect_scaled(&mut self, mut x: f32, mut y: f32, scale_x: f32, scale_y: f32, rect: &common::Rect<u16>) {
if (rect.right - rect.left) == 0 || (rect.bottom - rect.top) == 0 {
return;
}

unsafe {
x = (x * g_mag).floor() / g_mag;
y = (y * g_mag).floor() / g_mag;
}

let param = DrawParam::new()
.src(Rect::new(rect.left as f32 / self.width as f32,
rect.top as f32 / self.height as f32,
Expand Down

0 comments on commit cf5ee5b

Please sign in to comment.