Page 1 of 3 123 LastLast
Results 1 to 10 of 24
  1. #1
    Join Date
    Jan 2007
    Location
    Kansas City, KS
    Posts
    709

    Rico's XNA Volume 01 Noob Questions!

    Ok, so I finally got the first XNA dvd and I'm pretty excited about it. I'm not such a big game-creation buff but I'm doing this for the purpose of learning the language. I'm actually treating this like a class rather then just a set of videos so I'm deciding to post all of my questions here in this one thread.

    1st Question:
    -After learning how to create folders I guess the naming system changed. The buzz crew mentioned that there were several ways to call up a .cs file. So what they ended up doing is getting rid of the .Classes of the Hyperion.Classes of the GameManager.cs to refer back to that code. It makes a lot of sense to get rid it if you're just using the folder as a way to organize your work. So the question is, when would you actually use the following and which is the best method to use?

    ==> using Hyperion.Classes;
    ==> namespace Hyperion.Classes
    ==> Hyperion.Classes.GameManager.ShowTitleScreen();

    (I guess this question is geared more towards those who own the dvd. It would only make sense for those who have it.)

    p.s. I'm sorry if I'm not explaining thins well. I'm kinda new to the programming realm so please correct me if I miss write something. The least I can do is learn from you guys. Thanks !
    Last edited by Rico; 12-14-2008 at 05:52 PM.
    Rico - VFX Artist in training
    USA: Kansas: Kansas City = (GMT -6:00) (CST)

  2. #2
    Join Date
    Nov 2006
    Location
    UK
    Posts
    3,774
    If you have a majorly big project it useful to put classes in separate folders and so on, for smaller ones it doesnt matter quite so much.

    In terms of the best to use? Well if you're in another project and calling parts of your hyperion classes, I guess it depends. In your GameManager.ShowTitleScreen() call, it depends on the level of "using" you have.. because - if you are within the hyperon.classes namespace then you wouldnt need to specify the Hperion.Classes.GameManager.. because it would be just GameManager.. its a bit like a room in your house if you left something in the kitchen you wouldnt say "earth, country, county/state, town, nnn my road, the kitchen" to find it its just "the kitchen" .. However, for your friends house, you would say "friends house, the kitchen" because you arent there.. but you share maybe country and county/state, but for example if you're in the US and Im here in the UK you'd have to say UK, county, town, Lizs House, the kitchen .. coz you arent anywhere near me and unless you had said search UK.County then it wouldnt know to look here for me.
    Delphi !ROCKS!
    Got a question? Read this first!!!
    "You gotta help us, Doc. We've tried nothin' and we're all out of ideas"

  3. #3
    Join Date
    Jan 2007
    Location
    Kansas City, KS
    Posts
    709
    Thanks for the tip, LizRiley!

    2nd Question: Why do you have to define that an object is static?

    Ok... so the example with the multiple TV's and the one remote is good example... and I understood that, but what if you don't state that an object is static. How will it affect the program?
    Rico - VFX Artist in training
    USA: Kansas: Kansas City = (GMT -6:00) (CST)

  4. #4
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    1,215
    aahahh, I remember asking these questions when I started too

    Static objects are great! You don't have to declare them anywhere, so they are in scope of all classes in the nameSpace.

    Very handy for, say... an InputHelper class. You need the NewKeyboardState and the OldKeyboardState to be usable by both the Start screen, in Menu's, and by your main game, and by your player.
    Giving them all their own KeyboardState variable is do-able, but kinda annoying. Thats 8 KeyboardStates that all need to be re-polled every update.

    Instead, you give them all a centralised location to view from. Your InputHelper class. Now all you need to do is update these two KeyboardStates in the InputHelper class and everyone is looking at the same information.

    public static KeyboardState NewKeyboardState;
    public static KeyboardState OldKeyboardState;

    All of your other classes can now look at the current state by InputHelper.NewKeyboardState;
    There was never a need to say InputHelper inputHelper = new InputHelper();
    Very handy indeed, as you will soon come to see.


    Also, very handy if you have...say... a MenuItem class.
    You need a way to show users which MenuItem is currently selected. So you make all unselected ones green, and the currently selected one White. Hard coding in these colours is a pain as it's hard to find where you put it if you want to change it. And you might need to change it in several locations.

    However you need to make multiple instances of your MenuItem class. Afterall, it is a menu, and will need a few options (Start game easy, start game hard, exit, how to play etc.)
    To make ALL of your MenuItems look at the same colours, you make the Colour feilds static. Now, you can have an many MenuItem's as you want, but the static colours will only be defined ONCE.

    Code:
    //Common to ALL instances of MenuItem
    static Color ColorSelected;
    static Color ColorNotSelected;
    
    //Specific to each instance of MenuItem
    Color drawColor;

  5. #5
    Join Date
    Jan 2007
    Location
    Kansas City, KS
    Posts
    709
    Thank you Jacquesy for the great description! It's all slowly coming together now.

    3rd Question: I typed in 'prop' and hit tab twice expecting the following code snippet to appear:

    private int myVar;

    public int myProperty
    {
    get { return myVar; }
    set { myVar = value; }
    }
    This is the code I need:
    private string description;

    public string Description
    {
    get { return description; }
    set { description = value; }
    }
    Now, I have Microsoft Visual C# 2008 Express Edition installed and when typing in 'prop' and hitting tab twice I get this:

    Code:
    public int myProperty { get; set; }

    So, is the code snippet that I got for 'prop' in v2008 pretty useless or is there a different way to compile all the info I input into the previous code snippet into the different one that is provided by v2008?
    Rico - VFX Artist in training
    USA: Kansas: Kansas City = (GMT -6:00) (CST)

  6. #6
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    1,215
    type this in;

    private string myString;

    prop (tab) (tab) MyString

    Need to fill in your Description first.

  7. #7
    Join Date
    Jan 2007
    Location
    Kansas City, KS
    Posts
    709
    Well, yeah that's what I ended up doing in the end but you might might as well typed it all in. With the older version you got the whole code snippet and now with the newer version you get just a portion of it. It doesn't make any sense.
    Rico - VFX Artist in training
    USA: Kansas: Kansas City = (GMT -6:00) (CST)

  8. #8
    Join Date
    Apr 2004
    Location
    Sweden
    Posts
    140
    Actually it makes perfect sense. The code that you get from vs2008 is called an auto-implemented property and is a feature that was added with C# 3.0. As you write more code you'll notice that many of your properties will have the same standard form:

    Code:
    private type myVar;
    
    public type MyVar
    {
    
    get { return myVar; }
    set { myVar = value; }
    }
    With the new short code this is handled for you and an anonymous backing-field is created which can only be accessed via the get and set methods of the property. You can read more here

    Happy coding
    Se auderis delere orbem rigidum meum!

  9. #9
    Join Date
    Jan 2007
    Location
    Kansas City, KS
    Posts
    709
    Hey Experten! I didn't mean that it didn't make any sense at all... what I meant by that was that it didn't make any sense in why they would cut the code. I mean look at the code you get in v2005 versus what you get in v2008 when you typed prop and hit tab twice:

    v2005:
    Code:
    private int myVar;
    
    public int myProperty
    {
    get { return myVar; }
    set { myVar = value; }
    }
    v2008:
    Code:
    public int myProperty { get; set; }
    Thanks for the input, though, and the link. It was very helpful.

    Another Question:
    I'm not quite understanding the concept of TextBuffer. So what if the difference between:
    Code:
    TextBuffer.Add("Invalid direction.");
    and:
    Code:
    Console.WriteLine("What shall I do?");
    As far as I'm understanding they're both just writing out lines.

    p.s. I'm sorry if I'm asking some airheaded questions but sometimes I need explanations from two different people in order to truly understand something.
    Rico - VFX Artist in training
    USA: Kansas: Kansas City = (GMT -6:00) (CST)

  10. #10
    Join Date
    Nov 2006
    Location
    UK
    Posts
    3,774
    Not technically.

    Code:
    Textbuffer.Add("sometext");
    doesnt it adds it to the buffer, the reality is that buffer could then go to a socket across the internet, a log file, or your screen in some shape or form.. It allows you to setup so that whatever you may change in the future, you dont have to revisit every line you wrote Console.Writeline on.
    Delphi !ROCKS!
    Got a question? Read this first!!!
    "You gotta help us, Doc. We've tried nothin' and we're all out of ideas"

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •