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

Screen Flashes

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • 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
 
Sameera Abeysinghe
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic