- Home /
UI scrollable rect, get position on content based on mousePos.
I'm trying to make a tile based level editor (runtime) with a normal sized background. So if the user selects a background which is 1024*1024 and the tile size is 64 it would create 16 by 16 tiles. The tiles are just virtual tiles but when placing objects it needs to snap on the tiles.
Now my problem is with bigger backgrounds that don't fit in the editor. I'm using a panel (UI) with a scroll rect and a mask to pan the background in the window. Now my problem is how do I know the position on the background based on the mousePos in the window.
As you can see on the image here the background is bigger then the window you can see. Now when I click on the top left corner on the window I need to know that I clicked on tile [2,1] (red dot). And when I click were the blue dot is it would be tile [4,2]. Now the thing I'm struggling with is that when you move the background more to the right it would be a higher tile number.
How exactly do I get the proper tile based on the mouse position and the scrollable background image.
Here is the level editor how far I made it so far you can just select a background like sand to see it. (You can't do much with it yet)