Sign in to follow this  

2d tile based map

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

Hello there, I am a direct x beginner, and i am trying to create a tile based 2d map(like in a strategy game). My problem is: i want the map to be bigger than the screen and to navigate in the 4 directions to be able to view different parts of the map.It would also be great if i can zoom out to see more of the map and zoom in to see more details. Any help would be great. Thanks. note: i am using C# not C++ because this is an academic project for college so performance is not that important.

Share this post


Link to post
Share on other sites
you need to implement a camera system

tips
you need world coordinates and screen cordinates

whatever movement you apply to your camera , you apply it to your world in the opposite direction

Share this post


Link to post
Share on other sites
Just off the top of my head i would say somthing like this ...

create a full map image lets call it 3200 x 3200 (100 tiles wide and high if 32x32)

next create a struct or class or whatever like so ...

struct CAMERA
{
int x;
int y;
int width;
int height;
};


then when you draw to the screen ... im not good with DX but i would assume you would have to designate a source bmp, a destination bitmap and then the dimensions you wish to display. You would then just draw from the background bitmap at the x,y,width and height of the camera struct to your buffer or whatever.


you then control the where the camera is in relation to your character ..
if you move right do some logic to check if the camera exceeds the bounds of the background and whatnot if it doesnt ... camera.x += speed of your character and so on.

I am at work and kind throwing this all together so if it is hard to read im sorry >_< i keep getting interrupted. I dont know any DX but thats what i would "logically" do to scroll a camera and display it. I hope it helps if it doesnt i hope someone can explain it better =D

Share this post


Link to post
Share on other sites
Well, im no good at DirectX (trying to learn it....) But if you made a flat plain and rotated the camera above it, you would have a 2D map. Also, with that kind of setup, buildings and trees would have added depth, ex. When the camera moves the buildings will "bend" and you can see the sides of them.

Share this post


Link to post
Share on other sites
thanks rherm23, i tried that but the problem is DirectDraw wouldn't let me draw anything out of the bounds of the screen(if i did it doesn't render anything and displays an empty form).
frogtag, monkey4sale:
I have been trying to avoid d3d because i always assumed it would be harder and more complicated, and as i said earlier i am just trying to make an interface for a college project not a game.
However if there is no solution to draw bitmaps out of the screen bounds in DirectDraw, i think i would have to do as you said.
Thanks alot.

Share this post


Link to post
Share on other sites
"i tried that but the problem is DirectDraw wouldn't let me draw anything out of the bounds of the screen(if i did it doesn't render anything and displays an empty form)."

Again im at work and tired so i may be missing something. Is that in regards to the zooming or the scrolling? Im not sure i understand what you mean. >_< sorry.

As for the zoom

not being knowledgable of DX i would only assume you would have to use some sort of 3D area for the map area ... for example ..

(please correct me if im wrong here again ive never had to do this)

EXAMPLE
Create a bitmap of your background.
Have it sitting in a 3d space
set your camera a specific (default) distance from it.
Then when the user wants to zoom in / out .. move your camera in in and out. You might want to set a max and min zoom so the user doesnt have to deal with black areas on the sides.

Again im sure there is a more correct way to do this .. but with the knowledge i have this is how i would "try" to do it.

Share this post


Link to post
Share on other sites
Regarding drawing images semi off the screen:
I haven't used directdraw directly in quite a while however I do remember having the same problem with drawing pieces of a bitmap off the screen. If I recall correctly I got around this by clipping the source rectangle and modifying my destination rectangle so that I only drew stuff on the screen.

There may have been something about enabling clipping so that this was automatic but I remember it being easer to do it myself than enabling clipping. Again this was a long time ago.

I made the switch the SDL about a year after fooling around with directdraw and I never looked back. SDL uses directdraw in the background on Windows anyway so technically you are still using directx :)

Share this post


Link to post
Share on other sites
If you are insistent on using DirectDraw, be aware that BltFast does not respect the clipper, and any attempts to BltFast outside the screen area will cause a crash.

If you are using BltFast, you need to implement your own clipper.

It would be a lot easier to dump DirectDraw and do your 2D game with Direct3D using textured quads or the D3DX Sprite class. Once you have your head round it, it really is far easier to use.

Share this post


Link to post
Share on other sites

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