Tag Info

Hot answers tagged

54

First of all, XNA also uses C# too so it's the same programming language. And although the underlying API might have some differences from DirectX, that has nothing to do with jumping, so the same tutorials or answers should apply here. Also, there are numerous ways to implement this, depending on a lot of factors. What I'll describe below is just one of the ...


51

Here is an extremely detailed Sonic The Hedgehog physics guide. I would recommend reading it over, if not actually copying parts of it mostly-verbatim.


28

In a game which is controlled by a gamepad, where control inputs directly change GUI focus from one GUI button to another, those GUI buttons should be activated when a controller button is pressed. In a game which is controlled by a mouse (or if a gamepad is used to move a virtual mouse cursor around the screen), on-screen buttons should be activated when ...


20

There is no one perfect mapping that gives you a platform specific abstraction, because obviously most of the identifiers that make sense for a 360 controller are wrong for a PlayStation controller (A instead of X, B instead of Circle). And of course a Wii controller is another thing altogether. The most effective way I've found to deal with this is to use ...


19

It's quite tricky to implement, say, 'Mario-like' physics using a real physics engine. Last time I tried this, using Chipmunk, I modelled the player as 2 circles - a 'body circle' on top of a 'feet circle' The 'feet circle' had some friction, was non-bouncy, and fairly small. The 'body circle' was larger and frictionless, to avoid sticking to walls/steep ...


17

What you're trying to do is simple to solve without having to resort to doing any timing on the input (in fact I recommend you not to do so in this case - timing is more useful for scenarios such as limiting the firing rate of a spaceship). If you want for only the initial press of the key to be registered, the way it's usually done is: Keep track of ...


16

Can I discourage you from attempting to emulate a D-pad on a touchscreen device? The problems with emulating a D-pad on a touch screen are: the D-pad takes up screen space that you could be using for the game; unlike a real D-pad, an emulated D-pad offers almost no feedback: as a player, you can't tell which direction you're pressing in, neither by feel ...


16

It depends on the requirements of your game and hardware. Most games are usually interested in changes to input state, i.e. user presses the fire key and their weapon starts firing, user releases the fire key and their weapon stops firing, user presses the move key and starts moving, releases the move key and stops moving, etc., so an event-driven input ...


15

If you stop calling it "pushing forward" on the joystick/mouse, and start calling it "pushing up" (which is the way that most players think of it -- particularly the ones who don't play flight simulators), then the "invert Y axis" name makes complete sense, since pushing up causes the player to look down. Edit: The fundamental issue here is people's mental ...


14

Honestly I don't think using a physics engine is the right approach for something of that size domain with super strict requirements. Just write it all yourself. You'll get much better results by saying "move character up by x units in this parabola shape when holding down jump button for length y" than by having a bunch of knobs to tweak.


13

Distance-Based You will basically need to take two things into consideration: a threshold (inversely a deadzone) and the dominant vector. Given an enum like the following: public enum Direction { None, Up, Down, Left, Right } You would find the dominant direction (if the deadzone isn't in play) and use that. // You could make this user-configurable. ...


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

Recognising arbitrary shape vectors is hard! A simpler technique is to use a grid and count the edges crossed by the stroke drawn by the user. This list of edges is used as a "signature" which is compared against a dictionary of signatures of pre-defined shapes. Algorithm Sub-divide the input area into a grid (eg: 3x3 with infinite edges), and give each ...


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.


11

It's easiest to think of your order in a single frame, think of it as a series of dependencies. User input depends on nothing, so it goes first. Objects being updated depend on the user input, so they go second. Physics depend on the new updated objects, so it goes third. Rendering depends on the latest physics state and object updates, so it goes fourth. ...


10

I know this isn't the most useful answer, but unless you are porting a project over from another platform, I'd suggest reconsidering on the virtual D-Pad. Most implementations of virtual D-Pads have been poor at best, the lack of tactile feedback make them a poor choice for the platform. You are far better off looking at building an interface to your game ...


10

We used a state system, as you mentioned before. We would create a map that would contain all the keys for a specific state with a flag that would allow pass through of previously mapped keys or not. When we changed states the new map would be pushed on or a previous map would be popped off. Quick simple example of input states would be Default, In-Menu ...


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


10

The XNA Keys struct is not marked with the Flags Attribute which means that it's not legal to | a load of keys together like that. Keys keyCombo = Keys.Left | Keys.A; Console.WriteLine(keyCombo); Will print NumPad5, which is clearly not what you want here! You've never been able to do this in any version of XNA, I think the book is just wrong here :O ...


10

An SDL_KEYDOWN event is only sent when the key is first pressed. You will receive an SDL_KEYUP event when it's released. You'll want to handle moving in code which gets called every frame, not in response to an event. Inside Avatar::handle_input, you'll instead want to set variables to tell you whether each key is up or down, and update those variables as ...


10

Split this into several layers. At the lowest layer you have raw input events from the OS. SDL keyboard input, mouse input, joystick input, etc. You might have several platforms (SDL is a least-common-denominator lacking several input forms, for instance, which you might later care about). You can abstract these with a very low-level custom event type, ...


9

Did you search in the interactive fiction community? They still write parsers and some try to push the envelope by implementing new techniques such as natural language processing. See for example this link for articles describing approaches used: http://ifwiki.org/index.php/Past_raif_topics:_Development:_part_2#Parsing


9

Moving the joystick in a complete circle gives you the upper bounds of the joystick range, but the at rest (i.e. no input) position of the joystick can't be accurately determined from those values. You could assume that that rest position is the exact center of the available range but that is only true in ideal circumstances. Over time controllers wear in ...


8

When working on Wii titles, i found that a low pass filter on the accelerometer reading could be used as a reasonable approximation of the gravity vector component. Subtracting this from the real values then left me with a good basis stream for instantaneous gesture analysis. My low pass was around 1hz (just the average of enough packets of data) but tweaked ...


8

The best and simplest way to do it is to use your first idea and handle the WM_KEYUP/WM_KEYDOWN messages as well as the WM_SYSKEYUP/WM_SYSKEYDOWN messages. These can handle detecting the difference between left and right shift/control/alt keys, you just need the appropriate virtual key codes. They are VK_LSHIFT/VK_RSHIFT, VK_LCONTROL/VK_RCONTROL, and ...


8

You can use an Xbox wired controller, or you can pick up the wireless receiver which plugs into your USB port and lets you use the wireless controllers with windows. Here is a link to the wireless receiver.


8

You're on the right track. Getting a reference to a GameComponent from other GameComponents relies on GameServices. Revised code would look something like: var inputComponent = new InputComponent(this); this.Components.Add(inputComponent); this.Services.Add(typeof(IInputComponent), inputComponent); Getting the component back out from another component ...


8

two options: if "nested input" cases are at most three, four, I'd just use flags. "Holding an object? Can't fire." Anything else is overengineering it. Otherwise, you can keep a per-input-key stack of event handlers. Actions.Empty = () => { return; }; if(IsPressed(Keys.E)) { keyEventHandlers[Keys.E].Push(Actions.Empty); ...


8

I'd recommend profiling first and check if the touching check really is a bottleneck. Test with the maximal amount of objects that your game will use as a final product and see if you get frame drops. If it is in fact a bottleneck, I'd say go with the spatial hasing option and see if it gets better this way. But this is just my personal opinion. I'd say ...


8

You are creating a new game1 object in your PollInput command, since that's not your original game object, calling exit on it does nothing. Usual practice would be to pass in your existing game object in the constructor of your Input class. I'd also avoid creating a new Input object every loop of Update. Create it once and re-use it. This particularly ...



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