Tag Info

Hot answers tagged

35

The general approach to handling this in classic Win32 programming is to capture the mouse delta each frame, and then reset the mouse position to the center of the screen. You also want to make the mouse cursor invisible, obviously, as otherwise things look ugly. You can do the same thing in XNA, you just work with a slightly different interface. So you ...


15

Based on your comment, here's the code I'm using to convert tile x,y values to on screen coordinates. Now, it doesn't take into account "3d tiles", everything is considered as being on the same plane, so if you're writing a game where that matters, this code will not work. //this converts a map x/y coordinate into screen coordinates //public, static ...


13

What you are seeing is not input lag. To get the position of the cursor in Windows you can use WM_MOUSEMOVE or GetCursorPos. They both provide the position of the cursor after Windows has processed it, applying things like acceleration. This is the cursor position that Windows uses, including for drawing. And almost always what you want to use too. This is ...


12

You're on the right track with figuring out when the mouse is transitioning from down to up and writing a handler for that. For a lot of games, it's good enough to treat a mouseUp event as a click. Depending on your game, you're probably want to handle both events -- for example, in an RTS, you'll probably want to incorporate drag-box selecting as well as ...


11

The positions that you store within cursorX and cursorY hold the position of the cursor relative to top left corner of your screen monitor (since you add the ClientBounds to it). I'd guess that you used that exact position when drawing the circle, and since the Draw function takes a position relative to the top left corner of the game window, you'd be off by ...


11

When working with XNA in general you have to move from an event driven code paradigm to a loop driven code paradigm. Your update code loops 60 times/sec. So each time, look at the state of the mouse and if a button is down & pointer is within your rect, then branch to code you would normally place in an OnClick event.


10

While you can implement this using SDL_WarpCursor(), I've run into problems with that method on some platforms. I've had real problems with some platforms not reliably performing the WarpCursor() action, particularly when I've been calling it every frame. Also, remember that on many platforms, the cursor is handled at a higher frequency than your app. ...


7

You are starting to ask very important and complicated questions. First some general wisdom... In order to reduce the load on the server you should do as much as possible on the client. And in order to eliminate cheating, you should do as much on the server. As you see, these are diametrically opposite, and you will be in a constant conflict between these ...


6

You'll need to implement it yourself. Try looking at the tutorial at: http://bluwiki.com/go/XNA_Tutorials/Mouse_Input


6

XNA only gives you just enough to build your own input classes - and you should do so considering the utility they offer. I would recommend the mouse input class described in this blog post (source code). It detects a button being pressed, held or released, and lets you get that information either via polling or events. On a related note, the same blog ...


6

All you need to know is the relative angle between the player and the point where you are aiming at. It seems to me that you already have the angle, lets call that angle a. Now for the bullet to point in the right direction you just rotate the bullet sprite with angle a. Now for the movement/direction. You need to convert the angle to a 2D Vector, you can ...


5

You are probably forgetting to hook up your listener.


5

You forgot to put addMouseListener(this); to your frame/panel


5

Accordingly to http://lwjgl.org/javadoc/org/lwjgl/input/Keyboard.html you can make this like this: while (Keyboard.next()) { bool pressed = Keyboard.getEventKeyState(); int key = Keyboard.getEventKey(); if(pressed) processKeyPress(key); else processKeyRelease(key); } For more detail, you can google "Buffered input vs Unbuffered input" ...


5

A matrix simply applies some transformation on the coordinates of the object in order to send them to another coordinate system. In this case, the camera matrix converts world coordinates to screen coordinates. You can revert the process (that is, convert screen coordinates back to world coordinates) by transforming the screen coordinates with the inverse of ...


4

You should not use DirectInput. It has been completely deprecated in favor of RAWINPUT. The answer that uses WM_MOUSEMOVE is not the same as RAWINPUT and I expect it to not be fast enough. An example using RAWINPUT in a Win32 app is available on my blog


4

"He who would learn to fly one day must first learn to stand and walk and run and climb and dance; one cannot fly into flying..." You appear to want to draw a sprite that is always facing the mouse, correct? Then your first task must be to draw a sprite that is always facing something. Pick an arbitrary point and then do the math to draw the sprite so that ...


4

There is no 'best' - you need all of them. If I'm firing a gun, I don't want to wait for the mouse to be released to trigger the weapon firing effect. And if you're dragging a box around a bunch of units, you start the drag action on mouse-down. On the other hand, if I'm clicking a GUI item then I want to wait for the full click because that's what I'm ...


4

I assume you mean that forwards and backwards are working fine (from what I can tell they should). In order to move left and right you merely need to make the Vector2 perpendicular and use almost the exact same logic: public static class Vector2Extensions { public static Vector2 Perpendicular(this Vector2 vector) { // Swap y and x, and negate y. ...


4

Is this for providing an aiming guide for your player? If that's the case, then I suppose you want to draw the reticle so that it remains at a fixed distance around the player, but always facing in the mouse's direction. Here's how I would do it, based on what you currently have: // Distance to draw the reticle from the player float distance = 100f; // ...


4

How do you want this to behave? There are different ways to do this. A simple option is to just move the object by some fixed number of world space units for each screen space unit (pixel, say) that the mouse moves. Another option is to take the vector of mouse movement and project it onto the axis of movement through the normal projection/camera ...


3

Turns out you're in luck, kind of. http://superuser.com/questions/29432/using-two-mice-in-windows-7-dual-mouse-dual-cursor Because mice are just another kind of HID (human interface device) you can plug in as many as you want, but custom software is required to actually do anything with them. Beyond that link is a page to Microsoft's research called ...


3

You have somewhat answered your own question :) (everything after "so basically"). I don't have XNA here so YMMV with my code. Furthermore - it's (from what I can tell) usually a 1px border. Using Rectangles What you first need to do is determine the position in terms of your Viewport. What we do is create some rectangles and check if the mouse cursor is ...


3

When I was debugging mouse picking in my game, I had it set up to draw a line from my camera to where ever the picking function ended. It lets you know if the ray is going the right direction, and if the ray is ending too soon, or too late. In your case, I'd have it draw a line between nearPoint and farPoint. Make sure those are the rays you want. I ...


3

Let's get the obvious stuff out of the way, the tool is there: http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.mouse.setposition.aspx In fullscreen it is easy to use, just do some controlled repositionings and the edge problem is gone. For some other games this could lead to the problem of a trapped mouse in windowed mode, but if you ...


3

You're taking absolute world coordinates and feeding them to setLocalTranslation which, being a translation, sounds like it should take relative coordinates. i.e. if your character is at (10,10) and you click (10,20), I'll bet your character will move to (20,30) - it moved 10 horizontally and 20 vertically, not to (10,20). Instead you should find a method ...


3

In addition to using the code you have above you need to configure the axis in the input manager and name it correctly. The accepted answer here may be of help: http://answers.unity3d.com/questions/6106/implementing-the-scrollwheel


3

Vec2 delta = MousePos - ObjPos Float angle = atan2(delta.y, delta.x) Then use cos/sin to make a line if you want


3

The x and y you use here: bounds.setBounds(x, y, width, height); are the parameters x, y that are being passed into the method. I am assuming that there is also an x and y in your Tile class. So you either need to rename the parameters or use this. in front of your variables. public boolean inBounds(int x, int y){ Rectangle bounds = new ...


3

You can avoid the potentially O(N*M) containemt checks by simply calculating the tile's array index in O(1) time: int pixelCoordToIndex(int x, int y) { return ((y / tileHeight) * numTilesX) + (x / tileWidth); } Your code is then reduced to: System.out.println("Tile " + pixelCoordToIndex(x, y) + " clicked. X/Y val is (" + x + "," + y + ")"); ...



Only top voted, non community-wiki answers of a minimum length are eligible