Sign in to follow this  
WD Industries

Help with C# and XNA Classes

Recommended Posts

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!

Share this post


Link to post
Share on other sites
[quote name='WD Industries' timestamp='1341199527' post='4954747']
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.
[/quote]
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.

Share this post


Link to post
Share on other sites
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()

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this