1. Member
Join Date
Sep 2010
Posts
5
Rep Power
0

## Coordinates

Hello,

I'm making a game with map tiles, and I need help specifying the coordinates.

I was using a method witch only colored rectangles, but I Switched to Images.

Inside the "public void paint(Graphics2D g)"
Java Code:
```                                  //Set the tile to grass
Tile = Grass;
if (data[x][y] == BLOCKED) {
//If it's BLOCKED, draw Rock
Tile = Rock;
}
g.drawImage(Tile, null, null);```
How I draw the map:
Inside the "public Map()"
Java Code:
```		for (int y=0;y<HEIGHT;y++) {
data[0][y] = BLOCKED;
data[WIDTH-1][y] = BLOCKED;
}
for (int x=0;x<WIDTH;x++) {
data[x][0] = BLOCKED;
data[x][HEIGHT-1] = BLOCKED;
}
data[3][2] = BLOCKED;
data[3][3] = BLOCKED;
data[3][4] = BLOCKED;
data[4][3] = BLOCKED;
data[5][2] = BLOCKED;
data[5][3] = BLOCKED;
data[5][4] = BLOCKED;```
and the data is
Java Code:
`	private int[][] data = new int[WIDTH][HEIGHT];`
when I run it, all I get is a tile on 0,0

2. Perhaps it's me, but I can't get a handle on what you're trying to do or what problems you are having based on the information you've presented, as if you assume we know more about the inner workings of your program than we actually do (which is zilch). Please have a look at this link: How to ask Smart Questions.

Even though the title is somewhat condescending, it does provide many useful tips on how to provide enough information so that your question can be answered well. I know that the link has helped me out many times.

Luck!

3. Also, this confuses me:
Java Code:
`g.drawImage(Tile, null, null);`
since every Graphics#drawImage(...) overload has ints for the 2nd and 3rd parameters.

Again, much luck!

4. Originally Posted by Fubarable
Also, this confuses me:
Java Code:
`g.drawImage(Tile, null, null);`
since every Graphics#drawImage(...) overload has ints for the 2nd and 3rd parameters.
Since the graphics reference is of type Graphics2D, the compiler would map that to
Java Code:
`drawImage(Image img, AffineTransform xform, ImageObserver obs)`
db

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•