Tag Info

Hot answers tagged

36

Although you are targeting desktops, there will be players on (gaming) laptops and for some of them, it will be an inconvenience to get a mouse before being able to play your game. It would sound like a good thing to me, if you were to support alternative control schemes or customizable controls. This is not a very "sciency" answer - I've just run into this ...


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


22

It really depends what you mean by "assume". Are you making this assumption at the point of designing your gameplay mechanics? Or at the point of deciding whether or not to implement fully customizable key bindings? You could mean "I assume real gamers have a 3 button mouse, therefore I don't need to offer the option to rebind bayonet-thrust to a keyboard ...


17

If I understood your problem properly, you just want to shoot a bullet towards a mouse position. Here is how I would do: First of all, you must find the movement required for the bullet to get to the mouse, like so: Vector2 movement = mousePosition - bulletStartPosition; Then, you should normalize it to have a vector with a length of 1 so that you can ...


16

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


12

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


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

Many laptops lack a middle button, especially those with a trackpad, and you need special software to emulate it. Mac laptops have only one button. Right-click is pretty easy (two finger click) and not uncommon in Mac games, and the two finger drag to scroll isn't bad, but only in slower paced games. However, there is no concept of a middle click in the ...


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

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

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


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

If you're having trouble calculating the angle, you can use this: Vector2 target = mousePos - startPos; float angle = Math.Atan2( target.Y, target.X );


5

You are probably forgetting to hook up your listener.


5

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


5

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


5

Accordingly to http://legacy.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 ...


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


5

Some people use a trackball (some trackballs have no middle mouse button), trackballs generally are just as good pointing devices for players as ordinary mouses. The trackball I linked has no middle mouse button, and (at least on Windows) has an unusable scrollbar; despite these shortcomings I managed to finish quite few action games using it ;).


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

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


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

The solution is SDL_SetRelativeMouseMode. How can I have missed that.


3

The easiest way I see is to store velocity, when user clicks on screen. This velocity will define, which direction sprite should move and by what speed (so for example direction * spriteSpeed). Direction can be obtained by simple vector math: (TargetPosition - CurrentPosition).normalize() And then you will update sprites position each frame. So just add to ...



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