Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Fudance

Pages: [1]
1
Window / Multiple keys pressed
« on: January 22, 2009, 12:02:40 am »
Aha, dewyatt was correct, the problem was simple. I implemented the comparisons in an if-else block which meant if I successfully found a pressed key it would not cascade down and check for other keys being pressed as well. Changing everything to have its own if means every combination is now checked for.

D'oh, so simple. Implementing the bool suggestion makes the code more readble so that was worthwhile as well. Thanks for all the help, I'm sure I'll need more later!

2
Window / Multiple keys pressed
« on: January 21, 2009, 11:16:23 pm »
OK, I will try that, it never occured to try assigning the pressed key to a bool. If it doesn't work I'll post more of the code.

Thanks for the suggestions.

3
Window / Multiple keys pressed
« on: January 18, 2009, 04:49:08 pm »
Sorry, perhaps I should have elaborated further.

The code snippet below is pretty much ripped from the tutorials on the wiki. I test if the up, down, left and right keys are pressed in the 'if... else if' block and move the character appropriately. This works fine for movement where a single key is held down, so I'm trying to improve this further by adding the ability for the user to hold down multiple arrow keys at the same time to get diagonal movement.

At the moment I have a single 'else if' block to test if the user held down both the down and left arrow keys (the code I pasted in the OP).  I don't think this test is working how I think it should, it seems that my test to check for whether both the keys are down is always false.

Does that make more sense?

4
Window / Multiple keys pressed
« on: January 18, 2009, 01:32:33 am »
Hi,

I've just discovered SFML and am doing a little experiment game while I get my head around the main principles of the library. So far its been a blast but I've come unstuck when trying to test for multiple keypresses when using the GetInput member function. I'm trying to make a character move diagonally when 2 arrow keys (i.e. a user presses both down and left) are pressed but for some reason it doesn't work. This is what I'm trying to do:-

Code: [Select]

if....
...
...
else if (App.GetInput().IsKeyDown(sf::Key::Down) && App.GetInput().IsKeyDown(sf::Key::Left)) {
                       PlayerSprite.Move(-100 * ElapsedTime,  100 * ElapsedTime);
                }


I'm sure I'm doing something stupid here, but I'm pretty new to this and need it pointing out  :)

Pages: [1]