Stupid Question... Screen/Mouse to Isometric tile?

Need a little help, if someone has the time :slight_smile:

I am drawing my isometric tiles in an actual diamond shape. This is the method in use:

public Point isoPosToScreen(int tilex, int tiley)
{
int x = (this.tiles_width/2)(tilex-tiley);
int y = (this.tiles_height/2)
(tilex+tiley);

    return new Point(x, y);
}

I cannot seem to reverse it correctly however to change a screen X, screen Y back out to an isometric tile coordinate.

If someone can help me reverse this process so I can get the tileX, tileY back out, I would be very grateful.

Cheers,

Graham

Here, I posted this thread a few days ago back. http://www.java-gaming.org/topics/isometric-screen-space/27698/view.html

Hope I helped. :slight_smile:

Unfortunately, your method is not quite working with the way I am rendering the tiles.

Sad panda.

Thanks for the link though.

Oh, LordChandar, how are you rendering the tiles? I can easily modify the equation. Are you rendering it from the top of the tile?

This is the method that is putting the tiles on the screen.

I cannot seem to reverse this.

public Point isoPosToScreen(int tilex, int tiley)
{
int x = (this.tiles_width/2)(tilex-tiley);
int y = (this.tiles_height/2)
(tilex+tiley);

    return new Point(x, y);
}

My method basically starts the diamond in the center of the screen at the top.

The whole method is this:

public void WriteTile(Image i, int tilex, int tiley)
{
Point xy = getScreenIsoPos(tilex, tiley);

    xy.x+=(short)(this.vp_startX); 
    xy.y+=(short)(this.vp_startY); 
    
    xy.x -= (i.getWidth(null)-terrain_width);
    xy.y -= (i.getHeight(null)-terrain_height);
    
    vp.WriteImage(i, xy.x,xy.y);
    //vp.WriteDebug(i, xy.x,xy.y,tilex,tiley);
    
    if (tilex == 0)
    {
        if (tiley == 0)
        {
            System.out.printf("0:0 was written at %d:%d\n", (xy.x)+terrain_width,xy.y);
        }
    }
    
}

Okay, I reversed your equation and got this:

Its just solving for linear equations.


tX = ((screenX) / (tileWidth / 2) + (screenY) / (tileHeight / 2)) / 2
tY = ((screenY) / (tileHeight / 2) - (screenX) / (tileWidth / 2)) / 2

I didn’t simplify, sorry.

I really appreciate the help.

Math is hard for me. :slight_smile:

I don’t get how I have managed to write as much code as I have.

My code now works. I am in your debt.

Many thanks.

Remember to use [ code ] tag next time.

One more question…

If I try to translate the mouse coordinates it rounds weirdly… Any hints, tips etc? This function works great if the coordinates given are on the edge…

I’d like a function that translates the mouse/inner screen coordinates as well…

Thanks as always,
Graham

That is hardly specific, it is very similar to “it doesn’t work”. Such a problem description does not help anyone help you.

Why don’t you give an example of what you get and what you expect?

I think you have to round down. In my case, I had to render a bit less than it actually was also.