Hi - Im creating the game "Tanks" for the fun of it. Im fine with creating and adding the images and other inner game workings but I have digressed abit and have encountered a problem.
The problem is this: I have painted the tank image to the panel but wanted to paint n number of images to the screen according to the panel size. Let me give an example - each X is a tank:
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
The tanks should be painted in columns, and when 5 images have been painted or y( size of screen ) it moves to the next column and so on and so forth. When i tried doing this I could paint the first column and most of the second. I know that once y hits a certain value it should be reset to its initial value and x should be incremented. Maybe some code may help explain this:
public void paint( Graphics g )
{
super.paint( g );
Graphics2D g2d = (Graphics2D)g;
int x = 0; int y = 25;
System.out.println( "Paint method Called in Frame Class: "+callFrmeIncrmt+" times" );
callFrmeIncrmt++;
while( y <= 250 )
{
g2d.drawImage( myImage.getTankImage(), x, y, this );
y += 40;
System.out.println( "Images painted: "+imgCounter );
imgCounter++;
}
}
Also can anyone tell me if the paint method is automatically called twice by default using the above method? I have included a print statement in the paint method to track the number of times it is called. The output is:
Paint method Called in Frame Class: 1 times
Images painted: 1
Images painted: 2
Images painted: 3
Images painted: 4
Images painted: 5
Images painted: 6
Paint method Called in Frame Class: 2 times
Images painted: 7
Images painted: 8
Images painted: 9
Images painted: 10
Images painted: 11
Images painted: 12
Any ideas? Or am I yacking on too much?