0

I am making a game and have currently run into a problem where the graphics jitter. It starts to jitter from the top when you press the AWSD keys. The jittering starts from the top and spreads to the whole screen. Here is a video file: https://dl.dropboxusercontent.com/u/94218355/javaw%202013-08-30%2010-36-45-171.avi

Here is the game file:https://dl.dropboxusercontent.com/u/94218355/Game.rar The game file is so you can test it out yourself. Please look at Screen.java as I think this is where the error is hiding.

  • If you want people to read through your entire codebase, I would suggest you tell us where to look. – Cruncher Aug 30 '13 at 15:45
  • It's better to post the relevant data in your question. Most people are unlikely to want to read through a code wall, even less likely to want to download files onto their machines. – Hunter McMillen Aug 30 '13 at 15:46

2 Answers2

0

You should use double buffering or page flipping to avoid jitter.

mas.morozov
  • 2,666
  • 1
  • 22
  • 22
  • I am looking into it thank you. I tried double buffering with the same result. I generally use triple buffering. – user2733323 Aug 30 '13 at 17:48
0

This is an educated guess since no source is available. It is likely the issue is related to how you handle input, there is a common bug with input on java2d games due to the fact that there is an inherent latency between keypresses if the keys are registered through KeyListener interface. If you hold down a key (a) what you would expect would be aaaaa.. but what you actually get is a|inputlag|a|inputlag|... this latency is quite big (much higher than usual 60 FPS) and so when you hold down keys to move the camera about the camera seems jittery.

The simple solution is to use boolean flags for keys and set them to true once a key is pressed down and false once it is released, see my sample code here. or use keybindings.

Community
  • 1
  • 1
arynaq
  • 6,710
  • 9
  • 44
  • 74
  • I just added the source code. Sorry for forgetting the first time. – user2733323 Aug 30 '13 at 17:46
  • Yes it is as I suspected, since you are extending canvas and doing addKeyListener you are implementing KeyListener interface, which means you experience the latency I described. – arynaq Aug 30 '13 at 20:07