# [.net] Textures and Tilemaps

This topic is 4880 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Well i'm back again. I was wondering if there is any way to use a tilemap, and load it up as a texture. Than take only a certain section of that texture and use it to texture a poly. It seems like its possible, but can't seem to find the code for it. Was even thinking of maybe loading the tilemap as a bitmap first, than using GDI to cut a piece from the tilemap and create a new texture like that but that seems alot of work. Is there any direct way of doing this like specifing a rectangle area, or something similar to tilemapping in diretdraw? Slyprid

##### Share on other sites
Let's say you have 4 tiles on a horizontal row in the bitmap. So the U (texture) width of a tile is 1.0 / 4 = 0.25. And the width (pixels) of a tile is total width / 4.
Same goes for the vertical component.
Now you can complete this formula and 'cut' your tiles out of the texture. (mod and div come in very handy :) )
If you make your own formula your code will go smooth, and is optimized for your game.

##### Share on other sites
Well I get the idea on adjusting tU and tV of the texture, but how would you go about getting the anything but the first tile. Still not getting how to create a formula. Here is what i've come up with so far.

-------------
|1|2|3|4|5|6|
-------------
192x32 pixels

Say this is the tilemap I have, to get the first tile I change tU and tV to these values.

tU = 1 / 6
tV = 1

Now this works well for the first tile, but how would you go about getting tile 2 -6? Is there a way to shift the start point to something else besides 0,0?

##### Share on other sites
Well, you are texture mapping a quad (a shape with four corners), correct? that means that each corner has its own texture coordinate, for each of x and y.
so if we have a quad with texture coordinates like this:

(0, 0) ------- (1, 0)
| |
| |
(0, 1) ------- (1, 1)

it uses the whole texture, and if we set it like this:

(0, 0) ------- (0.5, 0)
| |
| |
(0, 0.5) ------- (0.5, 0.5)

it only uses the first quarter of the texture, and finally, if we set it like this:

(0.5, 0.5) ------- (1, 0.5)
| |
| |
(0.5, 1) ------- (1, 1)

it only uses the last quarter of the texture.

Perhaps this 'could' be a little clearer ;)

##### Share on other sites
oops, sorry, I just realized I inverted all the y-coordinates.

##### Share on other sites
LOL didn't even think about that. Thanks that worked out great.
Thanks for the help.

Slyprid

1. 1
Rutin
36
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 101
• 11
• ### Forum Statistics

• Total Topics
632974
• Total Posts
3009660
• ### Who's Online (See full list)

There are no registered users currently online

×