Help with C# and XNA Classes

Started by
2 comments, last by WD Industries 11 years, 9 months ago
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!
Advertisement

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.
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()
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!

This topic is closed to new replies.

Advertisement