I have a DirectX and C# question....

Started by
9 comments, last by ChurchSkiz 13 years, 10 months ago
Hello,

I need help in this important topic for me and I am not going to let it intimidate me to a point that I cower in the corner and say no I cannot do it! I am asking a junior question. I have a form with a good size picturebox object in the form. I want using DirectX to load 3 different separate tiles each size of 48 X 48, let us say 1st tile is 48 X 48 filled red, the 2nd tile is 48 X 48 filled blue and the 3rd tile is 48 X 48 filled green. I call each tile red, blue and green.jpg, respectively.

Using int [,] iMain = new int[0,0,0,1,0,0,0,2,0,0
1,1,0,2,0,0,3,0,0,1
0,1,1,1,1,1,1,2,0,0
0,0,0,0,0,0,0,0,0,0
3,2,0,0,0,1,0,0,2,0
0,0,0,0,2,3,0,0,1,0];
0 in the iMain is blank, no tiles draw, 1 represents the red, 2 represents the blue and 3 represents the green tile. 1st question is, how do I load the each tiles using DirectX and store them in a variable or texture and 2nd question how do I integrate the tiles in iMain and have them appear in the picturebox according to the plot of iMain?

Finally the most important question of them all when I use the mouse button and click on 1 I want a dialog box saying it is red and I press 2 to say blue and when I press 3 to say green but in the screen if the mouse is hovering over the red tile and I press it, it would prompt red in the dialog box regardless of the location of the red in the picturebox. All this be done on the Windows form and not full screen however, without removing multitasking system from Windows, meaning I can open menus, watch movies etc without performance effect. Anyone can help me in this would I would be greatly appreciate it.

Advertisement
Moving to For Beginners.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Thank you, I do hope someone in the beginner's section can help me.
I'm not going to answer your questions directly but instead rephrase them and ask you questions to be sure I, and others, can understand what you're even asking a little better.

Quote:Original post by foody1200
I have a form with a good size picturebox object in the form. I want using DirectX to load
How much DirectX do you already know? You don't say. The fact that you mention picturebox object in a form in one sentence and then DirectX in the next suggests you probably don't know much if any DirectX. There are today basically two (decent) ways to use DirectX with C#. The first is to use DirectX indirectly via the XNA development environment. The second is to use SlimDX which is a thin managed wrapper around DirectX. Additionally, DirectX is not the only way to display graphics in windows; a picturebox is another way that you seem to be using. Please elaborate on what you actually know.

Quote:1st question is, how do I load the each tiles using DirectX and store them in a variable or texture
To be clear, you want to know how to load your red.jpg, blue.jpg, and green.jpg files and be able to access them with a variable of some sort so that you can then copy them to your picturebox object?

Quote:2nd question how do I integrate the tiles in iMain and have them appear in the picturebox according to the plot of iMain?
So, given a)tiles and b)the given array you want to c)plot the tiles into a corresponding location based on that array?

Quote:Finally the most important question of them all when I use the mouse button and click on 1 I want a dialog box saying it is red and I press 2 to say blue and when I press 3 to say green but in the screen if the mouse is hovering over the red tile and I press it, it would prompt red in the dialog box regardless of the location of the red in the picturebox. All this be done on the Windows form and not full screen however, without removing multitasking system from Windows, meaning I can open menus, watch movies etc without performance effect. Anyone can help me in this would I would be greatly appreciate it.
You will probably need to start showing code so we can offer suggestions to your situation. I'm not even sure what you mean when you say "use the mouse button and click on 1". Are you saying that you want to click on a tile in your picturebox and have a dialog box pop up saying what color the tile you clicked on was?

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

Quote:Original post by nobodynews
I'm not going to answer your questions directly but instead rephrase them and ask you questions to be sure I, and others, can understand what you're even asking a little better.


Thank you, this is the best approach :)

Quote:Original post by foody1200
I have a form with a good size picturebox object in the form. I want using DirectX to load
Quote:How much DirectX do you already know? You don't say. The fact that you mention picturebox object in a form in one sentence and then DirectX in the next suggests you probably don't know much if any DirectX. There are today basically two (decent) ways to use DirectX with C#. The first is to use DirectX indirectly via the XNA development environment. The second is to use SlimDX which is a thin managed wrapper around DirectX. Additionally, DirectX is not the only way to display graphics in windows; a picturebox is another way that you seem to be using. Please elaborate on what you actually know.


You are right, my knowledge with DirectX is very limited if any at all. I am reading lots of online DirectX tutorial to get me more better grasp at it. Here is what I am doing, I am developing my own personal RPG maker, I have already used DirectX for sound and BASS.DLL for music (those are easy, really). My next goal is the map editor, with the map editor I want a good size view for the actual drawing of the map and on the left side of it a tileset display. I don't know if you can actually integrate directX in Windows without taking the entire Windows form, I have not done that yet to know how that works but from the tutorial I am working at it doesn't seem to be the case. So I want to draw my tiles on the map editor and select different tiles to draw on the map. I know XNA but XNA uses content pipline management it does not allow me to display beyond content management which is not good for editors but great for making hard coded xBox 360 games. Someone mentioned that I can use Texture2D.FromFile to load tiles but it is asking for GraphicsDevice and I don't know how to display that in the form like this: http://tkool.jp/products/rpgxp/eng/capt01.gif. You see how in the center there is the place to draw and on the left side you get to pick your tile, I thought to do this I need a picturebox with certain size on the middle of the form and it's left side another picturebox for the tiles (like the screenshot). So the Texture2D.FromFile(GraphicsDevice, Stream) for the XNA is not working for me because I don't what to integrate the GraphicsDevice. So I thought I could get the GraphicsDevice for Texture2D.FromFile to be use the picturebox (that did not work naturally and here I am showing you more my increase ignorance from the whole thing). So by reading all of this you can understand where I am coming from and newbie I am in this whole regard with DirectX, PictureBox and tileset, but I am NOT A NEWBIE ON THE CONCEPT of programming the concept of Object Oriented or static, void etc, or even how to code period. I thought to myself perhaps the best way is to get the tiles appearing first and from there I can grow slowly, slowly to a complete functioning map editor.

Now, can you tell me if with DirectX I can have something like the screenshot I showed you without the use of picturebox and still have menu, etc, etc and not take the entire form for one DirectX display screen? If that is the case, then can you help me at that?

Quote:1st question is, how do I load the each tiles using DirectX and store them in a variable or texture
Quote:To be clear, you want to know how to load your red.jpg, blue.jpg, and green.jpg files and be able to access them with a variable of some sort so that you can then copy them to your picturebox object?


I just want to be clear that I do know how to store variables and use them in a program, and I do know that storing things in XNA for tileset I need to use Texture2D and not Texture3D (for 3D games) if I am planning on programming to 2D games. So for example in XNA to load a tile I would do something like this:

tileset = Content.Load<Texture2D>(@"Content\tile");

and tileset is declared as Texture2D, but what if I want to load the red.jpg and store it in a variable using DirectX I cannot use texture2D and I cannot use int, string or boolean. What do I need for DirectX? Is it plain Texture?


Quote:2nd question how do I integrate the tiles in iMain and have them appear in the picturebox according to the plot of iMain?
Quote:So, given a)tiles and b)the given array you want to c)plot the tiles into a corresponding location based on that array?


Yes. Can it be done through picturebox? Can a picturebox represent a graphical screen and the picturebox have it's on X,Y coordinate and I can plot something in the picturebox that is located at 25, 98 in the picturebox?

Quote:Finally the most important question of them all when I use the mouse button and click on 1 I want a dialog box saying it is red and I press 2 to say blue and when I press 3 to say green but in the screen if the mouse is hovering over the red tile and I press it, it would prompt red in the dialog box regardless of the location of the red in the picturebox. All this be done on the Windows form and not full screen however, without removing multitasking system from Windows, meaning I can open menus, watch movies etc without performance effect. Anyone can help me in this would I would be greatly appreciate it.
Quote:You will probably need to start showing code so we can offer suggestions to your situation. I'm not even sure what you mean when you say "use the mouse button and click on 1". Are you saying that you want to click on a tile in your picturebox and have a dialog box pop up saying what color the tile you clicked on was?


If picturebox is not the best solution for map editor what would be for map editor in Windows form that allows a person to click anywhere in the coordinate of the map and plot a tile of selected choice from the tileset? Do you guys still need my code or you guys could help me without it?
Can anyone help me or further information needed? :)
Your question as is doesn't make a whole lot of sense. You would probably do better to explain what you are trying to do instead of asking specific DirectX question. For starters, if you are using a form, why do you want to use DirectX? Everything I'm reading is telling me that you're looking to overcomplicate something that's very simple.

XNA has the ability to store different textures, you can do a map editor in straight C# and a tiling system in XNA. Using straight DirectX is a step in the wrong direction.
Alright, I will ask my question in a simple form. I want to be able to make a map editor using Windows form (programming in C#) and have the user the ability to plot tiles on their maps and select tiles from the tilesheet and I want the user to be able to plot objects on top of tiles (where it doesn't destroy the original tile). Say I put an object called table, I want to be able to plot it on top of a tile called grass and the grass remains under the table. Then on top of the table I want to be able to put another object and it is called book and if I want I can plot another (object) book on top of the first book, so they start to stack on top of each other, i.e, they raise a little bit higher from the grass tile (depending on the graphics of the object). That is what I want, any help in this regard?
For just creating a map editor, you do not need and should not use DirectX. Stick with C# and use WinForms directly.

It's been a really long time since I did anything like this so my syntax might not be correct, but this is roughly one way to approach it using a radio button for different objects. In your main tiling window, something like this:

private void MainWindowArea_Click(object sender, EventArgs e){    if TableRadioButton.ischecked         graphics.drawImage("table.jpg", mouseposition.x,mouseposition.y)}


I can't remember what the syntax is but this should give you a general idea. Doing some WinForms tutorials should show you how to add an image and how to do mouseclick events, you'll just combine the two.

Also, I did a map editor awhile ago in C# using WinForms but it was a little more complex than what you are proposing. If you want to see what I did and how I did it you can get the source and project off my site:

http://www.adamsepanski.com/personal/gamedev/mapeditor/

If you run it, click the choose tile set button and navigate to the images section in the subdirectory and select tiles.bmp. That chooses a tileset into the editor (the size and number of tiles in the set you can change in the form window). Then you click load tileset to draw them on the window. Then you click on the tile you want to draw into the main window (the black area) and use your mouse like a paint brush. When you're all done you can hit Load Data Grid and it will save your window into an array that you can load into a game or an array.

THANK YOU SO MUCH! It is not the full solution BUT IT IS A PERFECT learning tool!! I can finally learn and understand the whole concept instead of looking at people's code and get soooo INTIMIDATED and think EVERYONE else figured it out except me!! Now with this I can know why this happens and how it is stored in memory, the best part you have them separated as objects (which is a great learning experience) and with this I can learn how the event of a mouse click and it's location determines the tile I have selected on a grid and how it stores the information and why it is store it like that! Also I never understood why it is stored like this in an Array {11,23,0,0,0,4,2,0,12,0,45,2,0,12,3,40,31} and what these numbers actually means and why not just have them stored like this {1,1,1,1,0,0,0,1,1,1,0,1,1,0,0,0,0,1,1}! Your source code would help me grasp everything a lot in the concept of map editor. Perhaps when I learn from your code and I will do a final exam and build my own Map Editor from scratch and optimize it better instead of copying code and modifying. It would make my life so much easier in the long run and perhaps even do a good half-decent job on my own map editor instead of where it is currently standing. In fact that is what I will do right now! I will take my big project and say you are going in pause mode now, because "I need to learn my fighting Kung Fu, before I challenge you!"

Can I ask one question? Is it possible you can join with me in my team with this project?? I promise you will be rewarded financially at the end of the project! If you are I will give you my personal email address and you can login to my MSN and we can chat live, I can ask you question if I am stuck somewhere and the best we can work together finish the project (you will have my source code you do part of the project and I do another part and then we merge our project as one). What do you say?

This topic is closed to new replies.

Advertisement