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

Pages: [1]
1
Window / Detecting if a key was pressed, not if it is always down
« on: December 27, 2009, 01:34:27 am »
Thank you all for the quick responses, it is now working perfectly. :)

2
Window / Detecting if a key was pressed, not if it is always down
« on: December 26, 2009, 11:59:54 pm »
Thanks for the help all, it seems to be partially working.

I'm currently using the Events system, but now if the left key is held down, it will work correctly for a few seconds and then repeatedly starts firing off. Is there a way to stop that from happening with the Events system?

It seems to be exactly the same as when a letter is held in a word processor.

Adi: Thanks, but that code doesn't work either, it does near enough the exact same thing as my original code.

Sorry if this is a stupid problem, but I am pretty new to SFML.

3
Window / Detecting if a key was pressed, not if it is always down
« on: December 09, 2009, 10:12:32 pm »
That got it working, thank you both for the help. :)

4
Window / Detecting if a key was pressed, not if it is always down
« on: December 09, 2009, 09:41:36 pm »
Oh okay, I will try that, thanks for the help.

5
Window / Detecting if a key was pressed, not if it is always down
« on: December 09, 2009, 09:17:48 pm »
Hello, I've been using SFML for a little while and I decided to create a DDR-like game with it.

The problem I have is, what is the best way to detect when a key has been pressed, and only execute the code which should be executed when the key has been pressed once?

The problem I have is that as long as the key is down, the game keeps executing the input code. (Basically to set the scale of a sprite to 0.5, otherwise it should go back up to 1). However the sprite always seems to stay at 0.5 when the key is held down, I want it to go to 0.5 when the key is first pressed and then return to 1.0.

Here is the code I'm using:

Code: [Select]

int NoteReceptors::CheckInput(sf::RenderWindow &Window)
{
const sf::Input& GetInput = Window.GetInput();

if (GetInput.IsKeyDown(sf::Key::Left) && TickL == 0)
{
TickL = 1;
ScaleL = 0.6;

}
else
{
TickL = 0;
}


As said above, it does not work, the code runs as if TickL didn't exist, therefore the scale always stays at 0.5 as long as the key is pressed.

I hope I explained it well enough, what I want to know is how to set it to 0.5 only when the key is first pressed, and then return to 1 even if the key is held down.

I also have
Code: [Select]
if (ScaleL < 1) {ScaleL += 0.1;} in the main loop so it does increase when the key is released.

Pages: [1]
anything