Tag Info

Hot answers tagged

19

The Application.Run call drives your Windows message pump, which is ultimately what powers all the events you can hook on the Form class (and others). To create a game loop in this ecosystem, you want listen for when the application's message pump is empty, and while it remains empty, do the typical "process input state, update game logic, render the scene" ...


9

The first thing you need to have a good grasp of is transforming 3D points to 2D screen coordinates and back again. Here are a couple of answers I gave about that subject; Understanding 3D to Screen, 3D to 2D. Now, to go from your mouse coordinate in 2D to 3D you need to do a 3D to 2D transformation backwards. This is fairly simple. An object/local ...


7

No. The viewport is a rectangular region on the backbuffer that determines the area in which the rasteriser draws pixels. A viewport (X,Y) of (0, 0) is always the top-left corner of the backbuffer (in XNA). You can freely move and resize it within the backbuffer. The backbuffer is the underlying surface that the GPU is drawing to. To resize it you have to ...


7

I can't tell from your (lack of) code, but you are probably just missing a stop to make sure that you don't handle tiles which have already been handled. At the top of the function you should put something like: if(thistile.hasbeenhandled){ return; } else{ thistile.hasbeenhandled=true; } Otherwise any two adjacent tiles that are to display empty ...


5

What I learned to do was to start your main project as usual with a Windows Game (4.0) then add your winform. Create a field to hold a reference to the Game1 class inside the form1 class Game1 gameEntry; Set the modifier on your pictureBox to public. In Program.cs : replace everything in static void Main() Form1 form = new Form1(); form.show(); // This ...


4

eBuisiness's answer is correct. But you're setting the HasBeenHandled flag after trying to update all the neighbors which then causes a stack overflow. You should instead set the flag before doing anything else. EDIT: You've also made typos in the if statements. if (Bottom.btn != null) set_text_of_button(Bottom.btn); if (Bottom_Left.btn != null) ...


4

I'm not sure if it will work in your specific problem but I also use Windows Forms with XNA and after trying many ways to get consistent mouse behavior across several different situations, I settled with this: public Vector2 GetMousePosition() { System.Drawing.Point point = this.PointToClient(Control.MousePosition); return new Vector2(point.X, ...


4

Separation of Concern, shuffling the board shouldn't be done by simulating a user, it should be done directly with the model (as in Model-View-Presenter) class Puzzle { IList<Direction> GetValidMoves(); void MakeMove(Direction); enum Direction {Up, Left, Down, Right}; } With a class similar to the one above you could shuffle the board in this ...


3

The way to do this is to embed it in a proper WinForms container. Here are the current links to the WinForms samples, since MS still haven't fixed up the old links :( WinForms Series 1: Graphics Device WinForms Series 2: Content Loading


3

Taken directly from the Winforms Series samples, here's the relevant bit of code related to your question. There was also a bit of commentary in there that might be useful. void BeginDraw() { // ... other code handling device resetting // Many GraphicsDeviceControl instances can be sharing the same // GraphicsDevice. The device backbuffer will ...


2

You need to manually include all of your content into the installer. In Visual Studio, right-click on the setup project, then click View, then File System. Under the "Application Folder", add a folder for Content and all of your XNBs, it should look something like this: As far as I know, there is no way to do this automatically, even if you include the ...


2

Are you running 64-bit Windows? When you say "stop working" do you mean the program just continues, or does the debugger terminate itself and your process? If you answered "yes," this is what may be biting you: In 64-bit Windows, the kernel will eat any exceptions that reach a managed/native transition. This often presents itself in managed applications and ...


2

Typically, I'll just create a bounding volume out of my mouse. The origin being where I clicked. Then, complete an intersection test by looping all objects. Then, sort the list you get back based on the criteria you want and select element 0.


2

In this video I show how do it with code...the projection/view is isometric, but all calcs are done in 3D... http://www.youtube.com/watch?v=axHp1f3RlHM When I calculate the mouse ray, I check for collision against a plane... but the procedure is analog to check against a list of boundingspheres associated with your objects. The algorithm should be similar ...


2

List is System.Collections.Generic.List, which is the standard resizing-array-backed vector class you'd see in Java ArrayList or STL vector. Tri is part of the other guy's code. OpenTK provides Vector3. If you're representing a model, you're going to need a few more definitions, including your definition of what a "triangle" is. Here's a rough guideline ...


2

I would recommend you to take a look at the model-view-controller concept. The model would be your map with all the objects on it. The view would be your graphic engine which visualizes the current state of the model. The controllers are the parts of the code which implement the game logic or the map editing capabilities. When your application is in ...


2

Microsoft has an official tutorial on this: http://xbox.create.msdn.com/en-US/education/catalog/sample/winforms_series_1 "or maybe you're writing a level editor and want to place Windows user interface controls around the 3D drawing surface" Basically, you embed your game as a control in a winform.


1

You should use the official sample. It demonstrates exactly how to get XNA to output inside WinForms. Any other method for doing this is almost certainly wrong and will either fail outright, or fail unexpectedly in certain circumstances. To use the official sample, you will have to extricate your existing code from the Game class. This means you must ...


1

OK, so after the positive reception of my design idea, I have gone ahead and implemented a prototype. For completeness, I'll describe the structure of my project below. Most importantly, it builds and runs, and the DI works great. Solution Structure (in VS2010) Solution Root: Client. Console Application. Startup Project. Server. Console Application. ...


1

I reworked the code to use the Windows.Forms mouse event methods rather than XNA's input methods, and that solved the click-through problem. Just had to use PointToClient and set up offset values (i.e., int offset = myPictureBox.Location.X) to subtract from my mouse coordinates. Here's the relevant code, for anyone who stumbles upon this problem in the ...


1

The STAThread attribute is used to indicate to COM that the application should use a single-threaded apartment (STA). This only affects COM objects, and is only required as certain dialogs that use COM (such as the FileOpenDialog) need the the correct threading model to be specified. To my knowledge very little (if any) game development will make use of COM ...


1

An idea I have considered but not yet tried: Draw an offscreen image the same as the real image but no textures etc. Simply draw your objects, each object in a different "color" where the "color" is really just an object number. To figure out what's under the mouse you simply look at the color of the pixel on the alternate image. Of course this is doing ...


1

Use the official sample, depending on what you want you may need more functionality. You can find more information at the link below. It includes a link to the PC template and sample. http://code.google.com/p/xna-game-menu/


1

You can use databinding. For instance if you have an object with a property NumberOfLoops which determines the number of loops being drawn: class CoilSpring { int NumberOfLoops { get; set; } } You can link that property to the value of the textbox doing something like this, for example on the form load event: textbox.DataBindings.Add("Text", coil, ...


1

You will likely get your answer by viewing debug output. Really, it's like a whole set of documentation there, embedded right in the debug spew. Run in debug mode and view the output in Visual Studio, or use a program like DebugView to see the messages. Be sure to enable the D3D9 debug runtime as the diagrams show in the linked answer above.


1

To add to Thomas's answer; any 2D based game would be a good idea. Look at a lot of retro games and try and emulate one you really like the look of. Games like Asteroids, Space Invaders and Mario are all challenging enough to, but not too drastically difficult to implement.


1

I wouldn't create multiple devices, I'd stick with one that you share across all render windows/controls. A device has some overhead involved in it's existence and you don't gain any advantages to having multiple instances, really. In fact, it can become much harder to share resources like textures between controls because they must be shared between ...


1

Win Forms only allows the UI thread to access and create UI Controls. There is an inbuilt way to run delegates on the UI thread for particular control: Control.BeginInvoke(): http://msdn.microsoft.com/en-us/library/0b1bf3y3.aspx. So you would need something like: if (BeginInvokeRequired) { startGameButton.BeginInvoke(new InvokeDelegate(delegate() ...



Only top voted, non community-wiki answers of a minimum length are eligible