| Poster | : stealthcoder | | Posts | : 7 | | Country | : Canada | | City | : Montreal |
| | | | Posted by stealthcoder on 19/01/2008 at 02:00:46
| | Hello,
I just found this site, and it is really amzing how much material is covered. I am definitely going to work through all of these XNA tutorials.
I looked over the first tutorial "Opening a window". I am just learning C# and object oriented programming, so I hope what I am about to ask is not too stupid.
The code that was added to the base XNA template file was
1) declaring the global variable:
2) Adding the method:
private void SetUpXNADevice()
{
device = graphics.GraphicsDevice;
graphics.PreferredBackBufferWidth = 500;
graphics.PreferredBackBufferHeight = 500;
graphics.IsFullScreen = false;
graphics.ApplyChanges();
Window.Title = "Riemer's XNA Tutorials";
}
|
3) Calling the above method from the Initialize() method:
NOW HERE IS MY QUESTION FINALLY:
Why are we declaring the global variable "device"?
I can get this code to compile no problem, but I don't see what the use of the following two lines of code:
and
device = graphics.GraphicsDevice;
|
If I comment out these two lines of code the program still compiles fine and give the same result.
Am I right that the lines of code
graphics.PreferredBackBufferWidth = 500;
graphics.PreferredBackBufferHeight = 500;
graphics.IsFullScreen = false;
graphics.ApplyChanges();
Window.Title = "Riemer's XNA Tutorials";
|
have no effect on the variable "device" that was declared at the start of the method SetUpXNADevice(). If this is true then why are we bothering with the variable "device"
Any clarification would be really appreciated.
Thank you. | |
|
|
| |
| |
| Poster | : stealthcoder | | Posts | : 7 | | Country | : Canada | | City | : Montreal |
| | | | Posted by stealthcoder on 19/01/2008 at 02:10:13
| | | Oops, I meant to say that the name of the tutorial is "Staring a Project", not "Opening a window". | |
|
|
| |
| |
| Poster | : Anonymous | | Posts | : | | Country | : | | City | : |
| | | | Posted by Anonymous on 18/08/2008 at 20:44:37
| | We create an instance of a graphics device. It's used starting from part 3:
device.VertexDeclaration = myVertexDeclaration;
device.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1);
|
| |
|
|
| |
| |
| Poster | : radulph | | Posts | : 218 | | Country | : germany | | City | : hamburg |
| | | | Posted by radulph on 19/08/2008 at 06:16:56
| | First, in OO there is nothing like global variables - only member variables. These can be accessed within the whole class they are declared in.
You're right: We don't neccessery need th device variable. Our class "Game1" extends the class XNA.Game and by this inherits the member "graphics".
Device is just a member of graphics, so you could access the device any time by writing:
graphics.device
instead of just device. And so, there would be no need to declare device in the head of you class.
So why t.h. we are doing this?! Simple:
Less typing. It's just a short cut. As you will see in the further tutorials, the device will be often accesed and you save some chars, not needing to write graphics. ... every time ;)
greets | |
|
|
| |
| |
| Poster | : riemer | | Posts | : 1388 | | Country | : Belgium | | City | : Antwerp |
| | | | Posted by riemer on 19/08/2008 at 12:38:21
| | | That's right, the only reason is: less typing. Nothing else. I was thinking about simply using GraphicsDevice, but I simply couldn't. Bad habit ;) | |
|
|