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

Author Topic: creating a click menù  (Read 1492 times)

0 Members and 1 Guest are viewing this topic.

koyuki

  • Guest
creating a click menù
« on: November 03, 2019, 09:47:06 am »
Hello everybody.
I have to create something that in response to my click will open an interaction menù, just like when we right click on desktop.
I was thinking about an sf::Quads maybe, wich will compare next to my mouse cursor, but i don't know if this is okay, i don't even know how to make it appear, do i need another view?

i don't even know what this thing is called, sorry if i am dumb, i am a beginner, so i would like to hear your teaches, and maybe if you could link me some guides :)

nfect

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: creating a click menù
« Reply #1 on: November 05, 2019, 08:21:06 pm »
you first need to check how events work

https://www.sfml-dev.org/tutorials/2.5/window-events.php

lower in that page, you'll find this piece of code

if (event.type == sf::Event::MouseButtonPressed)
{
    if (event.mouseButton.button == sf::Mouse::Right)
    {
        std::cout << "the right button was pressed" << std::endl;
        std::cout << "mouse x: " << event.mouseButton.x << std::endl;
        std::cout << "mouse y: " << event.mouseButton.y << std::endl;
    }
}

which means: if "right mouse button pressed, do this"

in the place of the "couts", you can add your code to make a "sprite", "rectangle",... appear at the location you wish (event.mouseButton.x, event.mouseButton.y), available from the event itself

sf::Quads is a primitive type, you can create your own shapes with sf::VertexArray, but I advise you to first play with what is already there before diving deeper, it's very complete already!
« Last Edit: November 05, 2019, 08:23:13 pm by nfect »