Results 1 to 4 of 4

Thread: Coordinates

  1. #1
    Witik is offline Member
    Join Date
    Sep 2010
    Posts
    5
    Rep Power
    0

    Default 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. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default

    Quote Originally Posted by Fubarable View Post
    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

Similar Threads

  1. coordinates and radius
    By tepong in forum New To Java
    Replies: 1
    Last Post: 08-21-2010, 06:38 PM
  2. Help with printing out new coordinates
    By tyke in forum New To Java
    Replies: 1
    Last Post: 05-10-2010, 06:34 AM
  3. Help with plotting x-y coordinates
    By Fidelcashflow in forum New To Java
    Replies: 3
    Last Post: 12-02-2009, 11:17 AM
  4. Getting mouse coordinates
    By nishant.4545 in forum Advanced Java
    Replies: 3
    Last Post: 07-20-2009, 11:28 PM
  5. button coordinates
    By jacline in forum AWT / Swing
    Replies: 2
    Last Post: 04-05-2009, 10:58 PM

Posting Permissions

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