• 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

Screen Flashes

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I've got a problem with the Breakout game I'm making.
The game uses a ball, a paddle, and lots of bricks. I have drawn all
the bricks into a JFrame, and then saved the picture as a BufferedImage.
This gives me 2 advantages:
1. When the ball and/or paddle are moving, the bricks do not all have to
be redrawn each time.
2. I can scan around the ball using the getRGB(int x,int y) method of
the BufferedImage class, to see if a point has the same colour as a
brick, and hence perform the correct actions.

But my current problem is that when the ball contacts a brick. I am
redrawing all the bricks minus the one that has just been hit, and then
saving the picture as a BufferedImage again...
This works fine, except for the fact the screen flashes white each
time a brick is contacted by the ball.

I'm not sure exactly whats causing this. I have considered just drawing
everything to the frame, but then I can't use the getRGB method to
test the colour of points around the ball.

Any ideas how to overcome this are appreciated. Thanks
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think u r drawing using the paint method. I had the same problem ones drawing in a panel. It can by done by double buffering but I don�t know it.
In your case,
Why does u draw your components?
Frame-setLayout (null) and add the components for bricks use jpanel with background color or a jlable with an icon. For the ball and paddle u can do the same. To move your components every time edit the setBounds method. Since the bricks is not moving (it is ?) every time setting the setBounds (for ball) method check if it in range with the brick

Hope this helps
I want mind testing your game for u
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic