Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Flickering

 
Tomm Schuman
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am making a game.
You can try what i have done so far here

But i have some problems about flickering in the game.
First one is when the frames of the player are drawn the first time it flickers alot. I have no idea why it does that because i load all the images when the game starts.

Then the other problem is when I draw the background which consists of many 20X20 pictures. If i have the game like 500x500 it works good but if i have it 1000x1000 it flickers in the lower right corner. Here is the code i use to paint the background:


I use this for painting:

Is there something wrong in painting this way. I have modified my game from a pacman tutorial which had painting done this way.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll have to implement double buffering for your display code, maybe even triple buffering if things get really complicated.
 
Tomm Schuman
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But I am using double buffering, how should i add triple buffering?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Game Development...
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a few ideas that may help out here...

First, at what rate are you refreshing the screen? Do you have a set Thread.sleep() time? From a while back I remember that a refresh of around 80 ms was OK (for the machine I was on), but that anything faster would flicker because it was just trying to refresh too fast...

Second, could be a separate threading problem if you are using multiple threads to control your game...

Third, it could be that 1000x1000 is just *too big* to be refreshed quickly enough without artifacts... in this case you'll either have to change your game architecture to be "quicker" (changing the redraw so it doesn't redraw the whole screen every time, but keeps track of "dirty" areas and only redraws those) or use libraries that let you get "closer to the metal" like JOGL or LWJGL.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic