RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

XNA Window

XNA Window

I have an XNA Game Window loaded into a Windows Form and would like to know how I can create some sort of...mouse bounds?

right now, when i check for mouse coordinates it checks the entire form, but i only want it to check when on the xna window and only in the xna window. how do i accomplish this?
 

Jeff

Lord
Storm33229;728703 said:
I have an XNA Game Window loaded into a Windows Form and would like to know how I can create some sort of...mouse bounds?

right now, when i check for mouse coordinates it checks the entire form, but i only want it to check when on the xna window and only in the xna window. how do i accomplish this?

depends on your code. But you should be able to do something like

Code:
if(mouseState.X > 0 && mouseState.Y > 0 && 
    mouseState.X < GraphicsDevice.PresentationParameters.BackBufferWidth &&
    mouseState.Y < GraphicsDevice.PresentationParameters.BackBufferHeight)
{
    //Mouse is inside the game window.
}

This is of course for checking inside the game, if you are checking from inside the windows form, thats another story. That would require more work and we would need to see code.
 
Well we have an XNA Graphical Device window inside a windows form, but a game class is never actually defined. We have a class that calls IServices, IGraphicalDevice something-or-another. I don't have the code in front of me right now. I was thinking to myself last night though, I should make it a game window. Apparently I may have been right.

We also need to check the X,Y of the mouse so that we can keep the 48x48 tile attached to the exact mouse location; right now its got a weird offset. Ideas?
 

Jeff

Lord
Storm33229;728815 said:
Well we have an XNA Graphical Device window inside a windows form, but a game class is never actually defined. We have a class that calls IServices, IGraphicalDevice something-or-another. I don't have the code in front of me right now. I was thinking to myself last night though, I should make it a game window. Apparently I may have been right.

We also need to check the X,Y of the mouse so that we can keep the 48x48 tile attached to the exact mouse location; right now its got a weird offset. Ideas?

All this stuff needs to be done inside the game, not the windows form. You need to check the x,y of the mouse per frame.

Code:
MouseState mouseState = Mouse.GetState();
int x = mouseState.X;
int y = mouseState.Y;

its that simple.
 
Top