dcsimg
horizontal lines drawImage
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Alexander_Torstling
Posted On:   Saturday, December 21, 2002 02:44 PM

Hi there! Im writing yet another tetris clone as an assignment at my college. My goal is to make it as flexible as possible, letting all logical components draw themselves. I use doublebuffering, and the Tetris "application" (which actually is a Canvas, listening to TetrisEvents eg ROTATE_LEFT), is scalable (listens to componentResized-events). It has all worked just great, until i started letting the pieces contain java.awt.Image's to make it all look fancy. I keep getting these horizontal, empty lines, in my picture. I have tried to be restrictive about using update(), but the problem persist. I have heard that the problem may lie in som bu   More>>

Hi there!



Im writing yet another tetris clone as an assignment at my college.



My goal is to make it as flexible as possible, letting all logical components draw themselves. I use doublebuffering, and the Tetris "application" (which actually is a Canvas, listening to TetrisEvents eg ROTATE_LEFT), is scalable (listens to componentResized-events).



It has all worked just great, until i started letting the pieces contain java.awt.Image's to make it all look fancy.



I keep getting these horizontal, empty lines, in my picture. I have tried to be restrictive about using update(), but the problem persist.



I have heard that the problem may lie in som bug in java runtime (i use win2000, java 1.3.1), showing especially where resizes are involved.



By the way: all drawImage()-calls return true.
I also have overwritten the isDoubleBuffered() -method
to return true.



I would very much appreciate som help here!



here's some sample code (the main drawing procedure and the bits own drawing system):



			
public void update(Graphics g) {



if (bg == null)

g2.clearRect(0,0,getWidth(),getHeight());

else

g2.drawImage(bg,0,0,spelSize.width+1, spelSize.height+1 ,this);



if (mainThread != null) {



mainArena.paint(g2,new Point(0,0),dsize);

klossFallande.paintAdjusted(g2,pointFallandePos,dsize);

}

else {

drawCentered(stopMessage, stopFont, Color.white, g2);

}

if (pause) {

drawCentered("Pause", stopFont, Color.white, g2);

}

paint(g);



}





public void paint(Graphics g) {

g.drawImage(imageDouble, 0, 0, this);



}




public void compResized(ComponentEvent e) {

dsize = new Point(getWidth()/NO_COLS, getHeight()/NO_ROWS);

spelSize = new Dimension(getWidth() - (getWidth()%NO_COLS),

getHeight() - (getHeight()%NO_ROWS));



imageDouble = createImage(getSize().width,getSize().height);

g2 = imageDouble.getGraphics();

repaint();

}





// The bit class and its painting:

public class ImageBit extends Bit {

Image im;

String filename;



public ImageBit(Image im) {

this.im = im;

}



public void paint(Graphics g, Point pos, Point dsize) {

g.drawImage(im, pos.x, pos.y, dsize.x, dsize.y, this);



}



public Object clone() {

return new ImageBit(im);

}



}





Thanx!

/Alex    <<Less

Re: horizontal lines drawImage

Posted By:   Rahi_Parsi  
Posted On:   Sunday, February 23, 2003 03:56 PM

Looking at your code, I don't see any problems with it. If you're getting horizontal lines mixed up with the output, then you probably need to use a MediaTracker to make sure that the image has loaded. Also keep in mind that when scaling images to a dimension larger than it's original one, you will get ugly blurring effects. A more reliable approach is to use a group of images as a texture pallete.



For example, let's say all the puzzle pieces will have a wood pattern. Then to draw the 'L' shape, you would draw the wood texture 4 times.

About | Sitemap | Contact