Jump to content
  • Advertisement
Sign in to follow this  
WD Industries

Help with C# and XNA Classes

This topic is 2204 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!