XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

Able to use objects across classes?

Last post 23/02/2009 00:20 by Izzy545. 2 replies.
  • 23/02/2009 00:11

    Able to use objects across classes?

    In my main game class I instantiate a player object and a map object I've created through classes (i.e. map.cs and player.cs).

    I'm wondering if there's any way I can reference that map object in my player object without passing it from one to the other through the Game1.cs?

    For example, I want to be able to say Map.tile[1,1] = 5 in my player class.

    If that doesn't make sense, I can try to explain further.

    Thanks everyone!
  • 23/02/2009 00:17 In reply to

    Re: Able to use objects across classes?

    class Player
    {
         public Map Map;
         ...
    }

    in your Game

    map = new Map();
    player = new Player();
    player.Map = map;

    now your player class can reference Map without going throught the game class.
    Game hobbyist hell-bent on coding a diabolical Matrix
  • 23/02/2009 00:20 In reply to

    Re: Able to use objects across classes?

    Awesome! I have no idea why I didn't think of that.

    Thanks!
Page 1 of 1 (3 items) Previous Next