neonblack

Event Jitter Fix

Aug 26th, 2013
1,691
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##------
  2. ## Display rounding error fix created by Neon Black.
  3. ##
  4. ## When certain slow display panning speeds are used, events will improperly
  5. ## round floating values to determine their position on screen.  This causes
  6. ## them to appear off from the tilemap by a single pixel.  Though minor this is
  7. ## noticable.  This snippet fixes this behaviour.
  8. ##
  9. ## This snippet may be used in any project.
  10. ##------
  11.  
  12. class Game_Map ## Rounds X and Y display values DOWN so the nearest 32 is found.
  13.   def display_x
  14.     (@display_x * 32).floor.to_f / 32
  15.   end
  16.  
  17.   def display_y
  18.     (@display_y * 32).floor.to_f / 32
  19.   end
  20.  
  21.   def adjust_x(x)
  22.     if loop_horizontal? && x < display_x - (width - screen_tile_x) / 2
  23.       x - display_x + @map.width
  24.     else
  25.       x - display_x
  26.     end
  27.   end
  28.  
  29.   def adjust_y(y)
  30.     if loop_vertical? && y < display_y - (height - screen_tile_y) / 2
  31.       y - display_y + @map.height
  32.     else
  33.       y - display_y
  34.     end
  35.   end
  36. end
RAW Paste Data