Movement?

I am trying to achieve Legends of Yore like movement. I know I need to get the offset and add that to the drawing coordinates but I just can’t seem to get it working.
Here is my current code:-


public void draw(Graphics g) {	
    xOff = 1184 - Player.x * tile;
    yOff = 1184 - Player.y * tile;
		
    for (int x = 0; x < map.length; x++) {
        for (int y = 0; y < map[x].length; y++) {
            switch(map[y][x]) {
        	case 1:
        	    g.drawImage(wall, x * tile + xOff * tile, y * tile + yOff * tile, null);
        	    break;
        	case 2:
                    g.drawImage(key, x * tile + xOff * tile, y * tile + yOff * tile, null);
            	    break;
            }
        }
    }
}

The 1184 is the world coordinates if you’re wondering too.
If anyone can help me, please leave a reply.

-Shannon

If the xOffset and yOffset are going to be the number of tiles, you don’t want to multiply the Player’s x and y by tile, since you are doing that in the drawImage method.

Still nothing Roi. Updated code:-


public void draw(Graphics g) {	
    xOff = 1184 - Player.x * tile;
    yOff = 1184 - Player.y * tile;
		
    for (int x = 0; x < map.length; x++) {
        for (int y = 0; y < map[x].length; y++) {
            switch(map[y][x]) {
                case 1:
        	    g.drawImage(wall, x * tile + xOff, y * tile + yOff, null);
            	    break;
        	case 2:
                    g.drawImage(key, x * tile + xOff, y * tile + yOff, null);
        	    break;
            }
        }
    }
}

This is my console output testing System.out.println(xOff + " " + yOff);.


896 960

-Shannon