[C#/XNA] New Concepts

Started by
6 comments, last by Kenny77 16 years, 7 months ago
I've been programming for a little while, and I have yet to come across something like this: currentPosition = originalPosition = initializationVector; It's from a book I'm reading, and I'm not sure what the result of that would be. Also, in the (Game) class constructer, there's the line: Enabled = false; In all the tutorials on Classes I've seen, I have yet to see one use something like this, can someone explain how and why it's used? Thanks a million.
Advertisement
currentPosition = originalPosition = initializationVector;

This simply assigns initializationVector to both originalPosition and currentPosition. A standard practice for the = operator is to return the assigned value, so originalPosition is assigned first, then it passes the intitialized value to currentPosition so it can be assigned.

I usually consider this bad style and sometimes hard to read. It's just the same to write that as...

currentPosition = initializationVector;
originalPosition = initializationVector;

...but I think this is more readable.


As for your second questions, it looks to me like a bool variable Enabled is being set to false. You'd have to investigate the context of Enabled to find out what effect that has.
Thanks, the reason I asked about the Enable = false; bit was because I didn't declare that variable anywhere.
Enable might be declared inside the Game class. Take a look at the class definition.
deathkrushPS3/Xbox360 Graphics Programmer, Mass Media.Completed Projects: Stuntman Ignition (PS3), Saints Row 2 (PS3), Darksiders(PS3, 360)
Quote:Original post by deathkrush
Enable might be declared inside the Game class. Take a look at the class definition.


That's what I was just thinking, but I pulled up the XNA documentation and Enabled is not one of the properties listed in the Game class. It may be a property inherited from a base class of Game. I suspect it's a window related property that controls whether the game window is visible and/or receiving messages, but I don't have XNA installed on this computer so I can't do any tests. Does the tutorial eventually set Enabled to true, like in an initialization function?
Are you sure that code isn't inside of a GameComponent or DrawableGameComponent? As said above, the Game class does not contain an Enabled field or property, so unless you declared that variable, you would get a compiler error if you put that in your Game class.
Try this.

Right click Enabled and select "Go to defintion" of "Go to declaration".
Should get you were the property or variable is declared :)
Oops, it's inside the ProgressBar game component, the class constructer of that. My bad.

This topic is closed to new replies.

Advertisement