![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
2-d graphics
Hey,
So I've started to make a tetris game for java. So far, I've created a bunch of classes. Now I need a class to control the drawing of my tetris shapes. What would be the best way to display an image to the screen (such as a jpeg)? Please help me out. I looked around google and sources tell me that if I don't use the correct methods, that the picture flickers a lot.
__________________
Death smiles at us all. All a man can do is smile back. |
|
|
|
|
|
#2 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 751
Rep Power: 3
![]() |
You probably dont want to actually write an image file. Look into the Swing classes, especially Graphics or Graphics2D. I think you modify the paint() method of the JFrame or JPanel you're drawing in to call the draw method for your stuff, using the Graphics object you get in paint().
|
|
|
|
|
|
#3 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
Jimbo is dead on. As for flickering, I wouldn't worry. Swing is double-buffered by default, IIRC.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
|
#4 |
|
Expert Programmer
|
What is the difference between Graphics and Graphics2D? They both appear to be for 2D drawing...
|
|
|
|
|
|
#5 |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,005
Rep Power: 5
![]() |
You don't need raster images for this. After all, the shapes are quite simple: they're basically squares. You might want bevelled edges with shading, in which case you can draw the block in its regular color, two adjacent edges (using line drawing) in a lighter color, and the remaining two edges in a darker color. You could do what I did, and use rounded rectangles. If you want to see if it looks good enough, the .jar file is here, though I think you'll need to save it locally before running it.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
#6 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
Quote:
I looked everywhere for swing methods i still can't find any. Please if anyone knows how to draw a jpeg to the screen your help in this would be greatly appreciated.
__________________
Death smiles at us all. All a man can do is smile back. |
|
|
|
|
|
|
#7 |
|
Hobbyist Programmer
|
Re: 2-d graphics
[delete me]
__________________
Who said i couldn't program sarcasm = raw_input('Type in a sarcastic remark: ')
|
|
|
|
|
|
#8 | |
|
Professional Programmer
|
Quote:
|
|
|
|
|
|
|
#9 | |
|
Newbie
Join Date: May 2006
Location: England
Posts: 2
Rep Power: 0
![]() |
Quote:
Graphics: // normal draw large rectangle
g.drawRect(10,10,300,300);
g.drawString("First Rectangle",10,10);Graphics 2D: // define a Rectangle2D object and ask g2D to draw it
Rectangle2D r = new Rectangle2D.Float( 200.0F,30.0F,50.0F,50.0F);
g2D.draw(r);
// redefine the position of the rectangle
r.setRect(20.0F,150.0F,50.0F,50.0F);Lisa |
|
|
|
|
|
|
#10 |
|
Professional Programmer
|
Just use an ImageIcon, and then g.drawImage().
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|