得到一个地形设置内部的瓦片的左上位置 [英] Getting a top-left position of a tile inside a tileset
问题描述
我有一个地形设置(全其它小图像的图像)。我想获得那些所谓的砖,所以我可以用它做什么小图像之一。我知道每瓦(他们都是一样大小)的大小。 我有两个等式:
X =(I%tiles_hor)* tile_h
Y =(I%tiles_ver)* tile_w
X =(ⅰ%tiles_hor)* tile_w
Y =(I / tiles_hor)* tile_w
其中的我指的瓷砖我想要得到的指数;
tiles_hor 是瓦水平的数量;
tiles_ver 瓷砖是垂直的数量;
tile_w 和 tile_h 的宽度和每瓦的地形设置,分别为内部高度;
瓷砖依次接收它们的索引,这样的:
01 02 03 04 05
06 07 08 09 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
所以每对位的它是地形设置内部的瓦片的索引。 比方说,我想要得到的04瓦(假设瓷砖各有一个32×32大小): 与第一方程:
X =(4%5)* 32 = 128。所以这是x位置内的图像是128
Y =(4%5)* 32 = 0,所以这是y中的图像内是0;
与第二式:
X =(4%5)* 32 = 128。所以这是x位置内的图像是128
Y =(4/5)* 32 = 0这里的是0,因为我们是第一圆第一八佰伴pression为最接近的次设备号(我不知道是不是我的前pression是正确的。请纠正我,如果它不是)。
请注意,我们正在考虑一个完美的正方形地形设置(在这种情况下,5×5)
我的问题是:
第二种适用于大多数情况下。第一站时,有没有完美的正方形地形设置的,并具有很高的高空作业。
所以我在做什么错呢?
另外,如何可以是让出一个非常重要的价值(tiles_ver和tile_h)可能是正确的一个公式?我在想什么呢?
X =((I - 1)%tiles_hor)* tile_w
Y =((I - 1)/ tiles_hor)* tile_h
I have a tileset(a image full of other small images). And I wanna get one of those little images called tile so I can do something with it. I know the size of each tile(they're all the same size). I have two equations:
x = (i % tiles_hor) * tile_h
y = (i % tiles_ver) * tile_w
x = (i % tiles_hor) * tile_w
y = (i / tiles_hor) * tile_w
where i means the index of the tile i wanna get;
tiles_hor is the number of tiles horizontally;
tiles_ver is the number of tiles vertically;
tile_w and tile_h is the width and height of each tile inside the tileset, respectively;
The tiles receive their index sequentially, like this:
01 02 03 04 05
06 07 08 09 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
So each pair of digit it's the index of a tile inside the tileset. Let's say I wanna get the tile 04(assuming the tiles have a 32x32 size each): with the first equation:
x = (4 % 5) * 32 = 128. So it's x position inside the image is 128
y = (4 % 5) * 32 = 0. So it's y inside the image is 0;
with the second equation:
x = (4 % 5) * 32 = 128. So it's x position inside the image is 128
y = (4 / 5) * 32 = 0. Here's is 0, cause we're first rounding the first expression for the closest minor number(i don't know if my expression is right. Please correct me if it's not).
Note that we're considering a perfect square tileset (in this case 5x5)
My question is:
The second works for most cases. The first stop working when there's no perfect squares tileset's and with a high height.
So what am I doing wrong there?
Also, how can be a equation that is letting out a really important value (tiles_ver and tile_h) can be right? What am I missing there?
x = ((i - 1) % tiles_hor) * tile_w
y = ((i - 1) / tiles_hor) * tile_h
这篇关于得到一个地形设置内部的瓦片的左上位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!