# Image looping issue

Show 40 post(s) from this thread on one page
Page 2 of 2 First 12
• June 3rd, 2012, 11:16 AM
Norm
Re: Image looping issue
The images for that print out would be on a row(y=115) going from left to right from 31 to 157.
What does the print out look like for when the images do not go where you want them to go?

No need to print values that don't change like Offset and length every time you print. Print them one time before the loop begins.
• June 3rd, 2012, 11:33 AM
Montario
Re: Image looping issue
That is in fact what the print looks like when the images printed are not where I want them to be. To see my actual visual problem with the images, look here: Attachment 1269

The images are at the moment meant to be in a U shape, though are in an L shape ith only one image printed on the other column.
• June 3rd, 2012, 11:35 AM
Norm
Re: Image looping issue
Quote:

images printed are not where I want them to be.
That print out was for putting images on a row (y=115)
What did you want that code to do differently? Where were those images supposed to go? What should be the x and y values to put the images where you want them?
• June 3rd, 2012, 11:52 AM
Montario
Re: Image looping issue
For testing purposes, I wanted the first column to start at y = 10, x = 10 and print 7 times to end up at y = 115, x = 10. The same principal would work for the next column and row. The problem came when only one image was printed at the second column. Basically to me at the moment it does not matter about the coordinates of the images as long as they print a hollow rectangle.
• June 3rd, 2012, 12:44 PM
Norm
Re: Image looping issue
Quote:

I wanted the first column to start at y = 10, x = 10 and print 7 times to end up at y = 115, x = 10.
If you want the y values to change (keeping the x value constant) then you will be drawing the images in a column.

What you posted was for the images to be in a row not a column. What does the code and printout look like for when you try to draw images in a column.

Quote:

problem came when only one image was printed at the second column.
Can you show the printout of the x & y values and the code?
• June 3rd, 2012, 01:38 PM
Montario
Re: Image looping issue
currentX= 115, currentY = 157 are the values printed out. Let me show you the whole current code so you can see what I am actually talking about.

Code :

``` private void drawMaze(Graphics2D g){ Graphics2D g2 = (Graphics2D)g;   int width = 5; //number of images to be drawn along the x axis. int height = 7; //number of images to be drawn along the y axis. int xOffset = 21; //width of image. int yOffset = 21; //height of image. int currentX = 10; //initial positioning of x (10+(21*5)= 115). int currentY = 10; //initial positioning of y (to+(21*7)= 157). for(int j = 0; j < height; j++) { g2.drawImage(cobblestone.getImage(), currentX, currentY,this); currentY += yOffset;   } for(int k = 0; k < width; k++) { g2.drawImage(cobblestone.getImage(), currentX, currentY,this); currentX += xOffset; } System.out.println("currentX= " + currentX + ", currentY = " + currentY); }```

I somehow want to implement this strategy for my next column and row. This code only produces an 'L' shape at the moment. I would like it to eventually make a full square.
• June 3rd, 2012, 01:41 PM
Norm
Re: Image looping issue
What part of the code works? Which of the four lines are drawn correctly: Left, top, right or bottom?

Which ones are you having trouble with?

Your println should be immediately following the call to drawImage so you see where EVERY image is being drawn. For example:

Code :

``` // draw first column at constant x for(int j = 0; j < height; j++) { // g2.drawImage(cobblestone.getImage(), currentX, currentY,this); System.out.println("currentX= " + currentX + ", currentY = " + currentY); currentY += yOffset; } System.out.println(">>>> Next"); // draw row at constant y for(int k = 0; k < width; k++) { // g2.drawImage(cobblestone.getImage(), currentX, currentY,this); System.out.println("currentX= " + currentX + ", currentY = " + currentY); currentX += xOffset; }```
• June 3rd, 2012, 02:14 PM
Montario
Re: Image looping issue
Pretty much all the code I posted you is working at the moment as it is only considering the left and bottom lines. I do not know how to do the top or right lines as each time I try it never works how I anticipate it to.

Here is the coordinates of every image:

currentX= 10, currentY = 52
currentX= 10, currentY = 73
currentX= 10, currentY = 94
currentX= 10, currentY = 115
currentX= 10, currentY = 136
>>>> Next Line
currentX= 10, currentY = 157
currentX= 31, currentY = 157
currentX= 52, currentY = 157
currentX= 73, currentY = 157
currentX= 94, currentY = 157
>>>> Restart
currentX= 10, currentY = 10
currentX= 10, currentY = 31
currentX= 10, currentY = 52
currentX= 10, currentY = 73
currentX= 10, currentY = 94
currentX= 10, currentY = 115
currentX= 10, currentY = 136
>>>> Next Line
currentX= 10, currentY = 157
currentX= 31, currentY = 157
currentX= 52, currentY = 157
currentX= 73, currentY = 157
currentX= 94, currentY = 157
• June 3rd, 2012, 02:19 PM
Norm
Re: Image looping issue
Quote:

I do not know how to do the top or right lines
For the top line:
What would be the y value for all the images? What would be the range of x values?

For the right line:
what would be the x value for all the images? What would be the range of y values?

If you can answer those questions, you should be able to write the for loops to draw the lines.
• June 3rd, 2012, 02:52 PM
Montario
Re: Image looping issue
Thank you Norm, the problem was I kept on mixing up my x and y values which returned a result I did not want. I also declared the variables holding the x and y value changes after the loop was executed.
• June 3rd, 2012, 02:54 PM
Norm
Re: Image looping issue
Glad you figured it out. Now on to the next problem.
Show 40 post(s) from this thread on one page
Page 2 of 2 First 12