Hello to everyone, I’m currently working on a Tile editor for one of my projects and i found a problem trying to make 2 things.
First, I dont know how to make a proper grid for my tiles
Two, I dont even know how to make it scrollable.
Here is an image:
As you can see it works properly but I dont know how to modify that
You should calculate the each cell constant for position. What I mean is you should know the sprite’s size and calculate on Unity screen how to put every cell builded.
For example:
My tileset is composed by a bunch of tiles that each one is 32x32 pixels. The space needed to put the tiles I have to calculate it using:
First: the “PPU” variant (Pixels Per Unit);
Second: using found texture PPU I can now know each sprite size on the Unity grid;
Supposing sp is a Sprite instance:
var ppu = sp.textureRect.width / sp.bounds.size.x;
In general PPU is 100, but you can change every texture PPU.
var spaceWidth = sp.textureRect.width / ppu;
var spaceHeight = sp.textureRect.height / ppu;
Considering you start on x = 0 and y = 0;
So the first tile’s position is (0,0);
The second is (0.32, 0)
The thrid is (0.64, 0) and so on.
“0.32” is PPU texture size (width or height) divided by PPU in case of 100 PPU.
I didn’t undestand quite well your second question. What do you mean about scrollable? The generated map scrolls by user’s movement? Scroll the camera? What?
Know I have a question for you: How did you rendered the tilesets on the right screenshot?