Jump to content
  • Advertisement
Sign in to follow this  
slyprid

[.net] Textures and Tilemaps

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!