How to solve shifting screen


18:05 06/06/2015


Threads: 4

Posts: 0

NOTE: I do not have a screen shot of this bug, but it has been reported, I will look for some and add to thread if possible. I am going to explain what causes it and how to fix it.

- After some time playing Lord's Road, the character becomes off center of screen. It eventually becomes unplayable in all browser.
- As spells are cast screen shakes back and forth for certain abilities.

Expected Behavior:
- The screen does not get off center from player.

Understanding Flash Variables: Flash variables are not precise when you add and subtract them repeatedly when dealing with screen resolution because flash scales the game client to the browser window. Let's assume the game wants to render 100 pixels in a screen that is 101 pixels wide. So it will increase the scale everything that is in that screen by 1%. So what flash does is takes the number 100 for the screen width and scales it to 101, which you would think is just 100+1 NO NO NO. Flash does not do this, it does 100 + 1.000001 or some other such calculation with a floating point number so your screen is 101.000001 pixels.

How spell screen shake effect works
So the screen shake from spell effects simply ads and subtracts a number from the screen value. And it is subject to the same imprecise calculations. Let's say screen shake factor is 5, so it goes 101.000001 + 5 then take that result which is also rounded and mangled with by flash and subtract 5. The end result is something like 101.000294. Eventually as the screen shakes more and more the variable becomes more and more imprecise and the screen will eventually shake off the view port.

How to solve this problem
You must explicitly set the variables for the viewport size to precomputed constant values. So you only perform the shake calculations one time ever and then just update the values. There may be other methods that ensure success, but if you always set the relevant variable to 100, whether it is 100.000001 or plain 100.0 it will always get set consistently.