Sign in to follow this  

Creating tiled backgrounds

This topic is 4578 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

I've been trying to learn DirectX lately and have been scouring the internet for information on where to start in regards to 2D sprite related stuff. According to Microsoft, DirectDraw has been deprecated since DirectX8 so I should use Direct3D, but most of the stuff I find regarding tiled backgrounds only talk about DirectDraw. I don't see any point in learning an outdated way to do things, so I'd like to learn it correctly the first time. I've been making good progress and so far I can create an animated sprite with Direct3D and move it around via keyboard or mouse. I can also create a background and make it scroll, and I've aligned my sprite to a grid and made it move smoothly between tiles. The problem is, I can't seem to find a way to draw the tiles. My first guess was to make each one a sprite but that doesn't seem right. My second thought was to use triangle strips but I haven't completely figured them out yet. I've also seen mentions of terrain mapping but that doesn't sound like the same thing. All of the tutorials I've found either talk about DirectDraw or more advanced stuff and I don't care about scrolling, or layers, or lighting, I just want to start with a simple square tiled background and work from there. So, can anyone point me to someplace I can find information on drawing a basic square tiled background with Direct3D?

Share this post


Link to post
Share on other sites
Ah, I think I see it now. A tiled background is simply a grid made up of square textured quads, which can be made from fans, strips, or lists. With the isometric view it's simply drawn at an angle and the texture is rotated at that angle. I guess I wasn't too far off with the idea of filling the page with sprites. I guess I don't see the difference between a textured quad and a sprite, though it's probably just something more advanced that I don't need yet.

[Edited by - Vimm on May 26, 2005 5:50:58 PM]

Share this post


Link to post
Share on other sites
I am currently writing an isometric tile engine via Direct3d and am using sprites. There is indeed almost no difference between a textured quad and a sprite, however I’m not quite following what you are saying here. Are you making this full 3D? Or is it a 2D illusion of 3D (isometric)? If the 2D is the case then you should look into the CopyRects function, or use sprites to take advantage of transparency (correct me if I am wrong in assuming that CopyRects does not support color keying). Its really your call, but if you wish to use the traditional 2d isometric approach then you would load in tiles that are pre-rotated/squished to how you want them to be displayed and then set the corners to transparent (the DX Texture Tool works well here). Here is the development thread for my system for you to look at if you need ideas. Good luck!

Share this post


Link to post
Share on other sites
I don't really have a set goal in mind yet, I'm just trying to learn some basics so I can use them in the future. That's also why I want to get things right the first time so I don't keep using them wrong later. I don't have any plans to use 3D but the DirectX SDK says to use Direct3D and not DirectDraw, so that's what I'm trying to do. Once I get some tiles going I'll try scrolling them, and after that I should have all the tools I need to make a simple game.

I looked up CopyRects and that seems to be a more memory efficient way for loading tiles, right? I just want to get something working for now but that's good to know.

Share this post


Link to post
Share on other sites
D3DXSprite is just a helper class made to do the same thing as a standard textured quad so people don't have to write up their own textured quad classes. I think there's some batching tricks included, which should make it a bit speedier than naive methods, though even the most naive methods should be "fast enough" on anywhere near modern hardware.

Share this post


Link to post
Share on other sites
Yay, it's working! Now I have a smooth scrolling map with one repeated tile and an animated sprite that can move smoothly between tiles. It was driving me nuts, it would only display one tile and only if I placed it in the upper left corner. Turns out I just needed to put ".0f" after all my whole numbers that are stored as floats. It's kind of annoying that it didn't convert int to float automatically, but I guess I'll just have to get used to throwing ".0f" everywhere.

I think I have enough basic tools now to get a simple game going. Thanks for the help.

Share this post


Link to post
Share on other sites

This topic is 4578 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this