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

Pages: [1]
1
Audio / Re: No compile errors, yet no sound.
« on: November 29, 2018, 08:08:41 pm »
Hey.
Your SoundBuffer and Sound are destroyed at the end of the scope they are declared in (like any local variable). In your code they are destroyed just after "s.play();" so it doesn't even have enough time for you to hear it.
Declare them somewhere else where their lifetime is longer.

Hello, thanks for the answer.

When calling sound.play(), isn't a new thread aumatically created to play that sound and when it ends the thread dies?

What approach could I use to play a sound whenever the player clicks left mouse button? I don't know, I might be missing something still...

2
Audio / No compile errors, yet no sound.
« on: November 29, 2018, 07:20:30 pm »
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
        {
                if (gameState->mPlayerFireCooldown <= 0.0f)
                {
                        // ...
                       
                        sf::SoundBuffer w;
                        w.loadFromFile("../assets/shot.wav");
                        sf::Sound s;
                        s.setBuffer(w);
                        s.play();
                }
}

Seems normal. Isn't it? I've spent thetwo hours on google and couldn't find a solution.

Any ideas?

Thanks in advance.

3
You can set the mouse position. To be honest though that just seems like a hack, so you don't have to write more code to handle joystick events properly. ;)
Mh. So, what do you suggest to achieve a sort of input independent cursor system?

4
General / Is there a way to move your mouse cursor with joystick's analog?
« on: November 11, 2018, 07:40:08 pm »
At the moment, I am handling every event with only the mouse. Including button clicks, hover in, out etc.

I was wondering if it is possible to treat the joystick as a second mouse: if the analog moves, so does the mouse cursor. Is there a way to do so?

Another possible approach I though: create a gameobject with the resemblence of a mouse cursor and move it alongside either mouse input or joystick input. But, in this case, what happens to my events? How would I translate

if (event.mouseButton.button == sf::Mouse::Right)
?

I'm open to suggestions.

Thanks in advance.

5
General / Re: Can't manage to have a clickable button.
« on: November 08, 2018, 05:14:56 pm »
Thanks, that's just the input I was looking for!

I came up with another solution, doesn't look clean. But it works:

if (event.mouseButton.button == sf::Mouse::Right)
                        {
                                if (event.mouseButton.x >= m_rect.getPosition().x
                                        && event.mouseButton.x <= m_rect.getPosition().x + m_rect.getSize().x
                                        && event.mouseButton.y >= m_rect.getPosition().y
                                        && event.mouseButton.y <= m_rect.getPosition().y + m_rect.getSize().y)
                                {
                                        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;
                                }
                        }

I dont know if there is a cleaner way, but at least I can proceed for now. Thanks again for your kind help!

6
General / Re: Can't manage to have a clickable button.
« on: November 08, 2018, 04:34:14 pm »
Why are you trying to cast the mouse's position to a FloatRect? The contains function accepts a point, not a rectangle.

Isn't the mouse's position a X/Y coordinate on the screen? If it isn't how do I get a point out of its position?

7
General / Can't manage to have a clickable button.
« on: November 08, 2018, 04:10:39 pm »
I know there are dozens of threads already, and I have read all of them. That's why I have no idea what I'm doing wrong.

I have a Button class:

class RectButton : public Widget
        {
        public:
                  virtual InputEventState ProcessInput(const InputEvent& event) override;
//more stuff

        private:
                float m_sizeX;
                float m_sizeY;
                sf::RectangleShape m_rect;
 

InputEventState RectButton::ProcessInput(const InputEvent & event)
{
        if (event.type == sf::Event::MouseButtonPressed)
        {
                if (event.mouseButton.button == sf::Mouse::Right)
                {
                        if (// what do I put here?)
                        {
                                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;
                        }
                }
        }
return InputEventState();
}

I know for sure I should put something like:

if (m_rect.getGlobalBound().contains(static_cast<sf::FloatRect>(sf::Mouse::getPosition())))

But, even there, I cannot convert FloatRect to Vector2f. Sorry, I'm 100% lost.

Thanks in advance.

EDIT: formatting

Pages: [1]