Jump to content
  • Advertisement
Sign in to follow this  
rherm23

couple of XNA questions

This topic is 2845 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

First question is on mouse clicks. I have a custom GUI_BUTTON and all i want it to do is when i click it .... to increment a variable. I then display that variable to the screen. so basically i have this

int count = 0;
bool pressed = false;

if (mouse is pressed)
{
pressed = true;
if (mouse is inside button bounds AND pressed)
{
increment count
pressed = false;
}
}

this makes the button work when i click inside of it. but when i click outside of it .... well thats diff. It doesnt incrememnt the count ... but when i click outside button then move mouse inside bounds .... it then increments. im not 100% sure how to make that stop. I know at some point i need reset pressed to false .... but ive tried putting that in a few spots and nothing seems to work. ill try and post code for this when i get home.

My next question is about fonts in XNA and C#.
I want to create a "GUI_LABEL" and have it basically have a series of strings like an array or something and have it display the current index of the array to the label.
so like

collection of strings called string_list
string_list.push_back("this is line 1");
string_list.push_back("this is line 2");
string_list.push_back("this is line 3");
string_list.push_back("this is line 4");
string_list.push_back("this is line 5");
// pardon syntax im like falling asleep as i write this and im sure its horrible /just trying to get the general idea out there

and so on.

then have a variable like

int current_line;
string current_string;

i want to be able to do something like

current_string = string_list[current_line]; again its the syntax thats killing me. im not too good with C# just yet and the difference of containers to C++ seems to throw me off.


and lastly ... lol sorry to be a pain
in my GUI_LABEL class would i need to pass a Spritefont object to draw text or some sort of SpriteBatch ... or should i just have a method that returns a string and leave all that to the draw method that is given to me when i create an XNA project.

Share this post


Link to post
Share on other sites
Advertisement
Hi there,

For your mouse clicking problem i suggest trying this:


if (mouse_inside_bounds)
{
if (mouse.LeftButton == ButtonState.Pressed && PreviousMouseState.LeftButton != ButtonState.Pressed)
{
//increment count
}
}



Change the 'mouse' variable to whatever yours is named.

The 'PreviousMouseState' variable is a global variable (you can name it whatever you want). Inside your update method add "PreviousMouseState = MouseState;".

If you hold your mouse button down outside the button then drag it inside, this prevents the code from executing, it will only execute if you click inside the button.

Hope that helps!

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!