drewaburden / resume

Résumé Quest
http://drewaburden.github.io/resume/
1 stars 0 forks source link

Camera panning player jitter #2

Open drewaburden opened 10 years ago

drewaburden commented 10 years ago

When the player moves close enough to the edge of the screen as to trigger the camera panning, the player movement appears to jitter very slightly. It's hardly noticeable. Some theories as to why it's doing this:

  1. The player isn't being rendered at a subpixel level as it should due to the TextureFilter of NEAREST. This has been an issue with other things as well, such as the background mountains not translating smoothly during parallax because they are moving so slowly (and they also have the NEAREST filter). I was unable to find a fix for this issue, so I simply made the mountains closer in their parallax depth.
  2. The delta time variable is not being passed down to each class; i.e., the delta time is being recalculated in some areas with Gdx.graphics.getDeltaTime(). This might be causing very slight variations in the delta times being used between classes, and this could potentially cause some things to be rendered in slightly the wrong place in the context of the rest of the frame.
drewaburden commented 10 years ago

I've been able to address the stuttering, but doing this causes the player to appear as if he is lagging behind the camera pan and then quickly catching back up every few seconds. It is also barely noticeable, but noticing the lagging is probably better than noticing the stuttering.

drewaburden commented 10 years ago

Something I did made the stuttering more noticeable, so now there's the camera lag and the stuttering. I can probably get rid of the camera lag, but who knows what that'll do to the stuttering. I'm still looking into this.

drewaburden commented 10 years ago

The camera lag was fixed with b4501656a4719fc86d253ece270c96dc7eb3ecf8. As far as the player jitter goes, it doesn't always happen. Sometimes it's really bad. Sometimes it's not noticeable at all. Another thing is that the sprites in the background jitter when the player moves while camera is sitting at the edge of the bounds, i.e. not moving. So, for instance, when the camera has reached the far right edge of Scene1, if the player moves around while not panning the camera, the sprites in the background jitter around. This leads me to believe that it might have something to do with the bounds checking.

drewaburden commented 10 years ago

Using one deltaTime per render iteration seems to have had no effect. I also tried using getRawDeltaTime() to get non-smoothed frames and that also appears to have had no effect. My next thing to try is to alternate the rounding of the camera position. So, on one iteration, it rounds up, then the next it rounds down, then up, and so on. Hopefully doing that will keep the camera from drifting away but keep it at a TextureFilter.NEAREST-friendly position.

drewaburden commented 10 years ago

I think I've fixed the background sprite jittering. I had forgotten to fix the other half of the problem that was causing the camera lag. This fix will probably be included in my next commit.

drewaburden commented 10 years ago

Alternating rounding of the camera position seems to have done nothing.

drewaburden commented 10 years ago

I may have finally figured out what is wrong. Instead of using Euler integration (simple position += velocity*deltaTime), I need to be using Verlet integration or something similar.

drewaburden commented 10 years ago

Well, that didn't seem to work either. I have absolutely no idea what is causing this.

drewaburden commented 10 years ago

This is possibly happening because the resolution is somewhat low. Allowing for more pixels to work with might help fix the problem (or possibly make it worse if the user chooses an even lower resolution, however unlikely). Initial tests for issue #30 seem promising.