Skip to main content
GameDev.net gamedev.net
🔒 Locked

Map-Maker using DX

Started by alex_myrpg Mar 13, 2005 at 7:03 AM 9 replies 2.1k views
Original Post
alex_myrpg
alex_myrpg
ok, this question is about my 2D tile-based RPG mapmaker. i have (and am) designing the ENGINE classes using DX9 for the actual game, but for my mapmaker i also want to make use of the same classes, even though i could just use normal VB.NET drawing functions - it saves a lot of work and makes everything conformed. however, i would like to know if this works by displaying it in a picturebox or even better, a pannel or form. if so, a snippet of code would be greatly appreciated (maybe SetCooperativeLevel and some other stuff with controls?). at the moment, i can only get it to display starting at position (0,0) of the screen. please reply asap. thanks p.s. i'm using VB.NET with managed DX9.0.
alex_myrpg
alex_myrpg
yo, anyone plz? i think this is a simple question :S it would really help for me to know...
locus
locus
Maybe wait for more than 3 hours. Not everyone who reads this will have the answer you need.
happysad
happysad
I did something similar with my sprite editor.
Isolate rendering code in an "Engine" project which you compile as a dll to be referenced from both your game and your editor(s). Then, create a Windows Forms project and create a class which inherits from UserControl. This will be the view control of your map. If you put it in a panel you will get scrolling for free. Draw your scene in the OnPaint method of the control.

One thing that caused me problems was that the control needs to respond to size changes by resetting the device. I took the necessary code for this from the Sample Framework.

Not sure if this is what you need... at least you know it is possible. If you need more information just ask.
alex_myrpg
alex_myrpg
thx, that really help, honestly! :D if you would mind posting your code for SetCooperativeLevel and for the resize, it'd be perfect :), but if u don't have it or the code's too much, don't bother.
happysad
happysad
Alright, I code in C#, so I hope you can handle that...

I put all my code for setting up the device, preparing to render etc. in a class called MyRenderer. This is referenced from the MapViewControl, if you choose to name your control that, under the name "renderer".

Your control should override these two methods:
protected override void OnPaint(PaintEventArgs e)		{			base.OnPaint (e);			renderer.RenderOnce();				}protected override void OnResize(EventArgs e)		{						base.OnResize (e);			if (renderer != null)			{				renderer.Resize();			}					}



The MyRenderer class then contains these methods:
/// <summary>		/// Call when a windowed app is resized - resets device to new back buffer		/// </summary>		public void Resize()		{			newClient = window.ClientRectangle;			// Check if the old client rect has changed			if (oldClient.Width != newClient.Width || oldClient.Height != newClient.Height)			{				// A new window size will require a new backbuffer				// size, so the 3D structures must be changed accordingly.				presentParams.BackBufferWidth = newClient.Width;				presentParams.BackBufferHeight = newClient.Height;				// Reset the 3D environment				if (device != null)				{					try					{						device.Reset(presentParams);					}					catch					{						throw;						//State.IsDeviceLost = true;					}				}				oldClient = newClient;								if(device != null)					base.Set2DView(); // camera setup depends on size of our canvas.											}		}		public void RenderOnce()		{			// draw the background (solid color)			device.Clear(ClearFlags.Target, ClearColor, 1.0f, 				0);			// build the scene			device.BeginScene();						Set2DView();			// call back			RenderScene();			device.EndScene();			device.Present();		}


the window object is a reference to the MapViewControl.

Here is the code used to set up the device:

CreateFlags createFlags;				Caps caps = Manager.GetDeviceCaps(0, DeviceType.Hardware);				if (caps.DeviceCaps.SupportsHardwareTransformAndLight)					createFlags = CreateFlags.HardwareVertexProcessing;				else					createFlags = CreateFlags.SoftwareVertexProcessing;				if (caps.DeviceCaps.SupportsPureDevice)					createFlags |= CreateFlags.PureDevice;				presentParams = new PresentParameters();				presentParams.Windowed = true;				presentParams.SwapEffect = SwapEffect.Discard;				device = new Device(Manager.Adapters.Default.Adapter, 					DeviceType.Hardware, window,					createFlags, presentParams);				Sprite = new Sprite(device);										Console.Out.WriteLine("Created device");
alex_myrpg
alex_myrpg
thanks, that's a big help :D i'm using DirectDraw rather than Direct3D but it shouldn't be a problem...
Sir_Brizz
Sir_Brizz
How do you get free scrollbars with panels??

also, how do you get your surface to associate with a panel without passing handles to crap all over the place? I haven't been able to seperate my rendering code from the level editor code whatsoever so far unless I make it REALLY messy...
It''s coming...Blox - an old new world at www.jaren.org
Sir_Brizz
Sir_Brizz
Maybe you can open my eyes to a better way to do this?

I don't know that autoscroll will work for me, because I'm building the surface right inside the panel. Are you opening a DDraw surface within the dimensions of the panel? If the surface has data on it that is larger than what is being clipped to the panel, will the scrollbars work? And will they do what they are supposed to? I'm not sure that they will.....
It''s coming...Blox - an old new world at www.jaren.org
alex_myrpg
alex_myrpg
ok, the best thing to do is to put a picturebox within the panel and paint onto that (make the picturebox as big as the map needs) OR the most efficient way would be to place two scrollbars and draw with DX onto the panel as a canvas.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.