Event Jitter Fix / Display Rounding Error Fix

Neon Black

The Classy Prostitute
Veteran
Joined
Mar 17, 2012
Messages
1,149
Reaction score
372
First Language
Sarcasm
Primarily Uses
Scroll down to the red bolded text if you just want the fix.

Recently it was brought to my attention that when scrolling the map with a lot of events on screen, the events would "jump" by a single pixel and would be improperly positioned.  I initially shrugged this off as lag, but when I saw the same effects on my absolutely awesome machine I wasn't quite sure what was up.  I decided I would look into it a little bit more.  When I tried to recreate it on my own by packing a screen full of events and then scrolling I was unable to reproduce the results.  It wasn't until I tested the issue with the demo in a related topic that I noticed the issue seemed to have to do with slow speed panning.

Essentially what I discovered is that events and the tilemap were rounding extremely low values from "display_x" and "display_y" differently.  The tilemap always rounded up while characters/events always rounded down.  What do I mean by extremely low values?  Because of the formula used to calculate scroll distance (2 ** @scroll_speed / 256.0) the display points can end up being values such as 15.5 pixels.  As mentioned earlier, the tilemap would round this up to 16 while the events would round this down to 15.  This would cause events to display 1 pixel away from where they were supposed to.

To fix the issue I modified two things to ensure that tilemaps and events would always get the same value.  First of all I added two methods to replace the normal reader methods for the displays.  In these I just multiplied by 32, used .floor to round down, switched it back to a floating point value, and divided it by 32.  This ensured that when received by anything that might use the display values, it was always rounded to the lowest values without any further need for coercing.  Secondly, I modified the two "adjust" methods used to determine the X and Y positions of events to reference the new reader methods rather than using the variable directly.

Anyway, all that done, here's the snippet.  Be sure to place this under materials and above all additional custom scripts since this is meant to be a bugfix of the default scripts.

Pastebin link: http://pastebin.com/XDd0tVWJ

Full Script:

Code:
##------## Display rounding error fix created by Neon Black.#### When certain slow display panning speeds are used, events will improperly## round floating values to determine their position on screen.  This causes## them to appear off from the tilemap by a single pixel.  Though minor this is## noticable.  This snippet fixes this behaviour.#### This snippet may be used in any project.##------ class Game_Map ## Rounds X and Y display values DOWN so the nearest 32 is found.  def display_x    (@display_x * 32).floor.to_f / 32  end    def display_y    (@display_y * 32).floor.to_f / 32  end    def adjust_x(x)    if loop_horizontal? && x < display_x - (width - screen_tile_x) / 2      x - display_x + @map.width    else      x - display_x    end  end    def adjust_y(y)    if loop_vertical? && y < display_y - (height - screen_tile_y) / 2      y - display_y + @map.height    else      y - display_y    end  endend
 
Last edited by a moderator:

Galv

Veteran
Veteran
Joined
Oct 1, 2012
Messages
1,267
Reaction score
1,514
First Language
English
Primarily Uses
RMMZ
Fantastic! I can't thank you enough for this. I couldn't work it out myself, very nice.
 

Kenen

Veteran
Veteran
Joined
Apr 3, 2012
Messages
262
Reaction score
155
First Language
English
Primarily Uses
RMMV
Your eye for precision and quality is outstanding, Neon Black. Thank you for the fix!
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,000
First Language
Tagalog
Primarily Uses
RMVXA
wow, it's cool that you even noticed that 1 pixel deviation...
 
Joined
Apr 30, 2012
Messages
216
Reaction score
35
First Language
Spanish
Primarily Uses
Long time no see,Neon Black.

Thanks you very much for the fix,you are a life saver.
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,198
Reaction score
425
First Language
indonesian
omg! i think you really have photographic memory. not everyone can notice that 1 pixel difference :D . good job neon :D .
 

Zachy

Veteran
Veteran
Joined
Mar 16, 2012
Messages
43
Reaction score
5
First Language
English
Primarily Uses
This is exactly what I needed, thank you for the great fix.
 

Fallun

Villager
Member
Joined
May 24, 2014
Messages
26
Reaction score
1
First Language
Danish
Primarily Uses
Wow! awesome! <3 needed this fix!! 
 

TheWhiteRose000

Veteran
Veteran
Joined
Jun 9, 2014
Messages
50
Reaction score
3
First Language
English
Primarily Uses
Scroll down to the red bolded text if you just want the fix.

Recently it was brought to my attention that when scrolling the map with a lot of events on screen, the events would "jump" by a single pixel and would be improperly positioned.  I initially shrugged this off as lag, but when I saw the same effects on my absolutely awesome machine I wasn't quite sure what was up.  I decided I would look into it a little bit more.  When I tried to recreate it on my own by packing a screen full of events and then scrolling I was unable to reproduce the results.  It wasn't until I tested the issue with the demo in a related topic that I noticed the issue seemed to have to do with slow speed panning.

Essentially what I discovered is that events and the tilemap were rounding extremely low values from "display_x" and "display_y" differently.  The tilemap always rounded up while characters/events always rounded down.  What do I mean by extremely low values?  Because of the formula used to calculate scroll distance (2 ** @scroll_speed / 256.0) the display points can end up being values such as 15.5 pixels.  As mentioned earlier, the tilemap would round this up to 16 while the events would round this down to 15.  This would cause events to display 1 pixel away from where they were supposed to.

To fix the issue I modified two things to ensure that tilemaps and events would always get the same value.  First of all I added two methods to replace the normal reader methods for the displays.  In these I just multiplied by 32, used .floor to round down, switched it back to a floating point value, and divided it by 32.  This ensured that when received by anything that might use the display values, it was always rounded to the lowest values without any further need for coercing.  Secondly, I modified the two "adjust" methods used to determine the X and Y positions of events to reference the new reader methods rather than using the variable directly.

Anyway, all that done, here's the snippet.  Be sure to place this under materials and above all additional custom scripts since this is meant to be a bugfix of the default scripts.

Pastebin link: http://pastebin.com/XDd0tVWJ

Full Script:

##------## Display rounding error fix created by Neon Black.#### When certain slow display panning speeds are used, events will improperly## round floating values to determine their position on screen.  This causes## them to appear off from the tilemap by a single pixel.  Though minor this is## noticable.  This snippet fixes this behaviour.#### This snippet may be used in any project.##------ class Game_Map ## Rounds X and Y display values DOWN so the nearest 32 is found.  def display_x    (@display_x * 32).floor.to_f / 32  end    def display_y    (@display_y * 32).floor.to_f / 32  end    def adjust_x(x)    if loop_horizontal? && x < display_x - (width - screen_tile_x) / 2      x - display_x + @map.width    else      x - display_x    end  end    def adjust_y(y)    if loop_vertical? && y < display_y - (height - screen_tile_y) / 2      y - display_y + @map.height    else      y - display_y    end  endend
This actually helped me a lot, as I got a lot of visual scripts running and its very taxing.

Wish I could smooth it out more but, beggars can't be choosers.
 

NeoPGX

~ King of Cuteness ~
Veteran
Joined
May 15, 2014
Messages
847
Reaction score
174
First Language
English (US)
Primarily Uses
N/A
What are the terms of use for the script?
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Say, does anyone know any other indie game development forums? Progress on my uni survey has been a little slow, so I wanna look into posting it around a bit more.
Due to the bullies' resurgence on Facebook and Twitter against my friend (and I since I defend), we've decided to move over to tumblr to try to obscure our presence, where we might finally be at peace working on games. If anyone wants my/our game's tumblrs to follow lmk. :kaojoy:
Is there anyone need help with anything except art and music?
is Gotcha Gotcha Games Inc. = KADOKAWA CORPORATION? I haven't found this topic yet, Want to know for credits on my game. Thanks.

Forum statistics

Threads
104,301
Messages
1,005,398
Members
135,825
Latest member
uniteditcare
Top