• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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: 4631
182
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic