SFML community forums

Bindings - other languages => DotNet => Topic started by: TheYoungGeek43 on August 26, 2018, 09:38:41 am

Title: Input detect once
Post by: TheYoungGeek43 on August 26, 2018, 09:38:41 am
Hello

I've problem my problem is I want when player pressed the left button of mouse my game detect one clic not 3600 clic

Thanks for your help ;)
Title: Re: Input detect once
Post by: Hapax on August 26, 2018, 09:51:29 am
Hi!

Take a look at the tutorial about events:
https://www.sfml-dev.org/tutorials/2.5/window-events.php
Take particular note of the mouse button pressed events section:
https://www.sfml-dev.org/tutorials/2.5/window-events.php#the-mousebuttonpressed-and-mousebuttonreleased-events
Title: Re: Input detect once
Post by: TheYoungGeek43 on August 26, 2018, 10:05:23 am
Hi
I've see that in internet but I don't understand where i initialize the Event in my main class i just this
                Window.DispatchEvents();
 
For the event
Title: Re: Input detect once
Post by: Hapax on August 26, 2018, 10:08:35 am
I apologise; I didn't notice that this was in the DotNet category.
I have little experience with C# so I'm unsure as the correct way to approach this situation and how it may be different from the C++ approach.
Title: Re: Input detect once
Post by: TheYoungGeek43 on October 05, 2018, 08:58:34 am
Hello

I've surrend this idea but this week i take my revenche but i don't know how I can do this

I want detect just once the input for detect the input always is pressed i use
            _window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
 
        private static void OnKeyPressed(object sender, KeyEventArgs e)
        {
            Window window = (Window)sender;
            if (e.Code == Keyboard.Key.A)
                Console.WriteLine("Hola");
        }
 

But i don't find for detect the input once

I'm french sorry for my english ;)

Thanks for your help ;)
Title: Re: Input detect once
Post by: Laurent on October 05, 2018, 10:00:18 am
The Window class has a function to disable repeated keyboard events.
Title: Re: Input detect once
Post by: TheYoungGeek43 on October 05, 2018, 03:02:33 pm
Ok but if i want detected the repeat i can't
Because i wan't to detected once for the attack but for the move i want detected always :/
Title: Re: Input detect once
Post by: Laurent on October 05, 2018, 03:08:38 pm
Moves should use real-time inputs (Keyboard and Mouse classes), not events.
Title: Re: Input detect once
Post by: billarhos on October 05, 2018, 03:19:39 pm
You can keep read repeatedly your key strokes and implement your "attack" with toggling a boolean  on key down and key up event.
Title: Re: Input detect once
Post by: TheYoungGeek43 on October 06, 2018, 08:53:50 am
Hello

I write the
            window.SetKeyRepeatEnabled(false);
 
But this don't work i try to write in the Update, in the constructor of my main class, in my function OnKeyPressed and in my function for create my window but this line don't work :/

Where i write i don't find.

Thanks and sorry :/
Title: Re: Input detect once
Post by: dabbertorres on October 06, 2018, 09:17:19 pm
Can you provide a minimal example (https://stackoverflow.com/help/mcve)?
Title: Re: Input detect once
Post by: TheYoungGeek43 on October 07, 2018, 01:36:32 pm
Sure sorry
OnKeyPressed function
        private void OnKeyPressed(object sender, KeyEventArgs e)
        {
            Window window = (Window)sender;
            window.SetKeyRepeatEnabled(false);
            if (e.Code == Keyboard.Key.A)
            {
                Console.WriteLine("Bou");
            }
        }
 

Update function
private void Update()
{
            _window.Closed += new EventHandler(OnClosed);
            _window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
            _window.SetFramerateLimit(60);
}
 

The Update function is call when i do the while window.isOpen

Thanks
Title: Re: Input detect once
Post by: Laurent on October 07, 2018, 08:22:59 pm
People usually put a link under "minimal example", please click and read it...

Your Update() function does stuff that should be done just once, I hope you don't call it every frame (and if you don't, then you should rename it). Also don't call SetKeyRepeatEnabled every time, do it just once.