Jump to content

  • Log In with Google      Sign In   
  • Create Account


Help with C# and XNA Classes


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
3 replies to this topic

#1 WD Industries   Members   -  Reputation: 127

Like
0Likes
Like

Posted 01 July 2012 - 09:25 PM

Hi there!

I'm still a beginner at programming - I usually fumble my way through coding and debugging. I need some help passing my "Mouse Position" to a class (so the class can determine if the mouse is hovering over the button).

I need help understanding how classes work as well as passing information to them when you use methods.

Basically - what I have now is a class called MouseManager (tracks position and buttons clicked), a class called Buttons (I am trying to get the update method to determine if the mouse is over one of the buttons) and the main program.

Here are some code snippets -

From Buttons.cs:

internal void Update(GameTime gameTime, MouseState currentMousePosition)
{
// Determine if mouse is over the button.
// I need help with MouseState currentMousePosition - I think this is where the problem is...
}

From MosquitoAttack.cs:

buttonStart.Update(gameTime, currentMouseState);


I can provide all of the code if it would help (well, I added it as .txt files). I am currently getting the following error:
The best overloaded method match for 'MosquitoAttack.Buttons.Update' has some invalid arguments.
and
Cannot convert from 'MosquitoAttack.MouseManager.State' to 'Microsoft.Xna.Framework.Input.MouseState'

Thanks!

Attached Files



Sponsor:

#2 DevLiquidKnight   Members   -  Reputation: 834

Like
0Likes
Like

Posted 02 July 2012 - 01:21 AM

I am currently getting the following error:
The best overloaded method match for 'MosquitoAttack.Buttons.Update' has some invalid arguments.
and
Cannot convert from 'MosquitoAttack.MouseManager.State' to 'Microsoft.Xna.Framework.Input.MouseState.

You are overloading a method incorrectly basically. Its expecting you to give it 'Microsoft.Xna.Framework.Input.MouseState' but instead you are providing it with your own object 'MosquitoAttack.MouseManager.State' you need to convert your object into the object it is expecting.

#3 anonymous22   Members   -  Reputation: 199

Like
0Likes
Like

Posted 02 July 2012 - 01:29 AM

Looking at your MouseManager class, I can't seem to find logic in your type structure.

Judging by the error you are getting, you are trying to pass an instance of a class you created as one of the built in XNA classes. If all you need in the Update method of the Buttons class is a MouseState instance, then you should define currentMouseState to be of type MouseState, not MouseManager.State, and initialize it with the currentMouseState field of the value returned by MouseManager.Read()

#4 WD Industries   Members   -  Reputation: 127

Like
0Likes
Like

Posted 02 July 2012 - 01:29 PM

Ah - okay, I think I understand what you are saying.

I will try to make some changes and I'll let you know!

Thanks so much!




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