0

I'm fairly new to programming but I've managed to learn how to set up a basic game loop with left/right/up/down controls. The only problem is that when the camera moves there are graphical glitches (jittering back and forth). I've looked into double buffering but I'm thinking the problem is probably with how the positions are stored, yet I can't figure it out.

Video of jittering

via GIPHY

Here is the project https://github.com/Im300/HexTest

Specifically, I think the issue is with the Hexagon class and the way it is stored and transformed by the

g2d.translate(cam.getX(), cam.getY());

function call by the GamePanel class. I've tried to fix it by changing the camera and hexagon class around (storing in double, rounding etc) but the glitches keep happening.

I used this implementation of a hex grid. (Algorithm to generate a hexagonal grid with coordinate system)

Many thanks

lm300Q
  • 1
  • 1

1 Answers1

0

After briefly taking a look at your code, it is likely because of the way you handle doubles vs ints. Perhaps some rounding error is the source of your problems.

I would suggest you use doubles for all of your "point" values for both your camera and hexes. Then you can convert those doubles into integers in your draw method. This will guarantee that any potential rounding error in your logic is reduced to virtually nothing.

Exonto
  • 51
  • 6
  • I've tried changing everything to doubles but depending on camera speed/line thickness etc the grid keeps acting up by vibrating slightly or stuttering. Even though both the camera position and hex position is saved in double and then truncated when drawn, it seems that the end result is still not granular enough for smooth rendering. https://giphy.com/gifs/JBzG7UcL5rNvy – lm300Q Jun 02 '17 at 02:15