aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Screen Flashes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Screen Flashes" Watch "Screen Flashes" New topic
Author

Screen Flashes

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 743
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

Joined: Nov 15, 2004
Posts: 104
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Screen Flashes
 
Similar Threads
Points on an Image
Error in one of my classes
Java Intersects
Breakout Applet
The game "Breakout", stuck with collision checking