Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Trouble getting variables from services in XNA


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 gchewood   Members   -  Reputation: 236

Like
0Likes
Like

Posted 30 August 2012 - 08:26 PM

I'm fairly new to using game services in XNA and I'm having trouble using them to return values. I have a character interface ICharacter that has a method to return the characters position. This interface is implemented by my input control which handles the character movement.

If I use this same method from my main game class, where the input control was instantiated, it returns the correct position. However, if I add the ICharacter interface to game services and then try to return the position vector from within another game component, it returns zero. Help!
(I can post code if necessary)

Sponsor:

#2 gchewood   Members   -  Reputation: 236

Like
0Likes
Like

Posted 30 August 2012 - 09:08 PM

Ok, I apologise for speaking too soon. It was a silly mistake. In case anyone ever has a similar problem, make sure you're not making the mistake I was (creating game componenets and then creating completely new ones when adding to the game services:

Bad code
public Game1(){
cam = new Camera(this);
input = new InputControl(this);
this.Services.AddService(typeof(ICamera), new Camera(this));
this.Services.AddService(typeof(ICharacter), new InputControl(this));
}

Good code
public Game1(){
cam = new Camera(this);
input = new InputControl(this);
this.Services.AddService(typeof(ICamera), cam);
this.Services.AddService(typeof(ICharacter), input);
}

Edited by gchewood, 30 August 2012 - 09:08 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS