[.net] Need Help With Tilemap

Started by
4 comments, last by web_scripter 18 years, 10 months ago
Has anyone here made a game that uses Direct3D to display a 2D tilemap in C#? I am having a real hell of a time drawing a single tile correctly. My textures keep coming out slightly distorted. I posted a detailed explanation of my problem in the DX forum. Anyways, my code looks solid so I'm beginning to suspect either driver problems or .Net bug. I've Googled around and can't find any tilemaps implemented in a .Net language to look at. This is such a pain. Doing a tilemap with GDI+ was super easy, but too slow. Thus my need for D3D. If I can't get this to work I may need to fall back on DirectDraw (yuck).

Shedletsky's Bits: A Blog | ROBLOX | Twitter
Time held me green and dying
Though I sang in my chains like the sea...

Advertisement
what were you thinking about!!>!?!?!!?!?!?! DUDE Check out the D3DXSprite interface!!!! your code is solid but one function can do what all of ur code is doing!!! but 3x's better
sry in ur case , C#, look under the Direct3D namespace for the Sprite class i found it in the dx managed doc
DONT YOU DARE USE DirectDraw!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
P.S. Reason: dont ask stupid questions, ill pwn you
Whateva. I'll use 12 deprecated APIs which constitute hate crimes. Whateva I do what I wan!

On the DX sprite interface:

I hear it's slow and have no interest in sinking time into it and later determining that it is, indeed, slow. What I'm doing is pretty simple and did not require much time at all to get running. It also makes panning and zooming and rotation trivial. Dunno if the sprite interface does that. Dun care.

Shedletsky's Bits: A Blog | ROBLOX | Twitter
Time held me green and dying
Though I sang in my chains like the sea...

EITHER use the textured vertex buffer:

CustomVertex.PositionTextured[] verts = new CustomVertex.PositionTextured[4];verts[ 0 ] = new CustomVertex.PositionTextured( x,y,0.0f, 0.0f, 0.0f );verts[ 1 ] = new CustomVertex.PositionTextured( x,y,0.0f, 0.0f, 1.0f );verts[ 2 ] = new CustomVertex.PositionTextured( x,y,0.0f, 1.0f, 1.0f );verts[ 3 ] = new CustomVertex.PositionTextured( x,y,0.0f, 1.0f, 0.0f );

Use a triangle fan to render it.
The last two arguments are how to display the texture

The texture has these coordinates
0.0f,0.0f ------ 0.0f,1.0f
| /|
| / |
| / |
|/ |
1.0f,0.0f ------ 1.0f,1.0f

So just assign the vertices to the proper texture coordinate and the texture will render coorectly.

OR use sprites.
Just create a sprite and load a texture with a color key and then render it.
Sprite spr = new Sprite(device);Texture tex = TextureLoader.FromFile(device, "texture.bmp", 0, 0, 0, Usage.Dynamic, Format.Unknown, Pool.Default, Filter.None, Filter.None, Color.FromArgb(255,255,0,0).ToArgb());

This topic is closed to new replies.

Advertisement