• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

New to programming and java - very simple asteroids program which flickers (buffering issue?)

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys

Im new to programming and java and these forums so please bare with me, below is the code i am currently working on (following a textbook) but ive checked over the code and as far as i can see everything is correct but when i run the applet i just get a black and white flashing screen. I am assuming that it is something to do with the buffer or painting but i just cant figure out what. If anyone could point me in the right direction that would be great (the applet is a VERY simple version of asteroids which i will improve upon but need to get this portion working first)

If you have any ideas awesome shove me in the right direction if not thanks for looking anyway

 
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Ben,

the idea is to let the game thread do all the updating: the updating of the objects AND
the updating of your BufferedImage. So it is the run() method where all the updating should
take place; not in the update(Graphics g) method.

And when that is done, you issue a repaint(), which, IIRC, issues first
the update(g) method, and then the paint(g) method.

So, do all the updating of both the objects and the BufferedImage in the run() method,
then issue repaint(), and all that you have to do then is:




And you could try to experiment with Thread.sleep(..); Java is fast enough to let you do more than 50
redraws per second. I remember from the old CRTs that a refresh rate of 50 caused a lot
of flickering. Well, that should be far less with the current LCD's of course.

Greetings,
Piet
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic