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.


Topics - MickeyKnox

Pages: [1] 2
1
General / How to build SFML on linux with a custom build folder?
« on: September 08, 2021, 09:46:32 pm »
The guide for building SFML with cmake https://www.sfml-dev.org/tutorials/2.5/compile-with-cmake.php seems to be focused on Windows.

What I've tried so far:

$ cmake ./build
CMake Error: The source directory "/home/ingmar/src/SFML/build" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.

$ mkdir build
$ cmake ./build
CMake Error: The source directory "/home/ingmar/src/SFML/build" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.

Should I just just move CMakeLists.txt to build? Will pathes in there still be correct?

Running cmake . does work, but the guide explicitly suggest to specify a build folder. How do I do that?

2
Window / sf::Mouse::isButtonPressed returns always false for XButtons
« on: September 04, 2021, 06:45:03 pm »
Consider this minimal example to reproduce the problem:

int main()
{
    sf::Window window(sf::VideoMode(800, 600), "test");

    sf::Event event;

    while (window.isOpen())
    {
        while (window.pollEvent(event))
        {
            switch (event.type)
            {
                case sf::Event::Closed:
                    window.close();
                    break;

                case sf::Event::MouseButtonPressed:
                    switch (event.mouseButton.button)
                    {
                        case sf::Mouse::XButton1:
                        case sf::Mouse::XButton2:
                        case sf::Mouse::Left:
                            if (sf::Mouse::isButtonPressed(sf::Mouse::XButton1))
                                std::cout << "XButton1 pressed" << std::endl;
                            else if (sf::Mouse::isButtonPressed(sf::Mouse::XButton2))
                                std::cout << "XButton2 pressed" << std::endl;
                            else if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
                                std::cout << "Left button pressed" << std::endl;
                            else
                                std::cout << "No button pressed" << std::endl;
                            break;
                        default:
                            break;
                    }
                    break;
            }
        }
    }
}
 

The event for the XButtons is fired, yet sf::Mouse::isButtonPressed returns false; the output is "No button pressed". The problem doesn't occur for the left mouse button, the output is as expected "Left button pressed".

Have I found a bug? Or is there something funny with my mouse? Tested on Ubuntu 20.04.

3
Window / [SOLVED] Prolonged key press timeout
« on: August 30, 2021, 07:53:59 pm »
When pressing a key an Event is fired for that key being pressed. After that there is a timeout, in which no Event is fired for the same key still being pressed. The timeout seems to be about one second. After the timeout an Event is fired every frame.

Is it possible to control the lenght of this timeout, setting it to 0? Or is it possible to simply disable the timeout?

4
Graphics / How to interpret the local bounds .getLocalBounds() of sf::Text?
« on: November 10, 2020, 10:19:54 pm »
I'm drawing a background sf::RectangleShape for a sf::Text. After setting the Font, CharacterSize and the String I ask for its local bounds, to initialize the background rectangle:

sf::FloatRect textSize = text.getLocalBounds();
sf::RectangleShape background(sf::Vector2f(textSize.width, textSize.height));

Both the sf::Text and the sf::RectangleShape have the same position. But the background rectangle is always a little bit too small for the text. Top and Left are OK, but at the Bottom and the Right the text sticks out of the background rectangle.

Why is that so? What can I do about it?

5
Window / [SOLVED] How to select a Sprite from Mouse position?
« on: June 26, 2020, 02:20:56 am »
This is basically what I'm doing:

auto mouse = sf::Mouse::getPosition(window);
if (sprite.getGlobalBounds().contains(mouse.x, mouse.y))
    ...
 

That doesn't work as expected. A few issues arose:

1. The sprite's global bounds rect left/top is ALWAYS 0:0, although its position is not. Is this the expected behaviour?

2. sf::Mouse::getPosition(sf::Window&) doesn't respect position of the View, it seems to be the same as  sf::Mouse::getPosition(). I'm running in Fullscreen.

No I guess I could get the game world mouse position by adding the View position manually. And maybe if I set left/top to the position of the Sprite I could ask if it contains the mouse then.

But before trying this, I want to ask: What is the canonical way to get the Sprite under the mouse given my scenario with a game world much bigger than the desktop?

6
Graphics / [SOLVED] How to move the View?
« on: June 19, 2020, 07:50:27 pm »
window.getView().move(0, 1);

doesn't work, because Window::getView is const, while View::move isn't.

How am I supposed to move the View?

7
Graphics / Is Sprite::setTexture() a heavy operation?
« on: May 10, 2020, 12:29:13 am »
Should I implement some sort of check if my sprite already has the right texture set?
Or is there no overhead if I set the same texture again and again in the game loop?

8
General discussions / Animated GIFs in SFML
« on: May 04, 2020, 09:47:41 pm »
Hi all,

I made a small class to display AnimatedGIFs in SFML:

https://github.com/SFML/SFML/wiki/Source:-Animated-GIF

Let me know what you think.

9
Window / Is a call to window.isOpen() required to see anything?
« on: November 21, 2019, 01:00:10 am »
I've written minimal program to display an image:

int main()
{
    sf::Texture texture;
    texture.loadFromFile("foo.jpg");
    sf::Sprite sprite(texture);

    sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "foo");
    window.draw(sprite);
    window.display();

    usleep(1000000);

    return EXIT_SUCCESS;
}
 

This doesn't display anything. Of course, when I replace usleep with:

    sf::Event event;

    while (window.isOpen())
    {
        window.waitEvent(event);
    }
 

I can see my picture. However, when I omit the call to window.waitEvent(), I don't see anything again. Calling only window.waitEvent(), not inside the window.isOpen() loop, doesn't display anything either.

My question is why? Is window.isOpen() or window.waitEvent() doing something hidden in the background that is neccessary to display anything?

10
General / How to load images in a dedicated thread?
« on: December 30, 2013, 01:35:42 am »
Hi, i'm writing an application where i want to load images throughout the hole time,
the application runs. Loading images however slows the application noticebly for a moment.
Therefore, i want to load the images in a dedicated thread. But i'm having trouble to figure
out the best approach to do that.

Just to clarify:
I'm not  having trouble with the Thread data type and C++ programming,
but i'm seeking help with my code design.

Thanks~

11
Graphics / Zooming like in googlemaps
« on: May 31, 2012, 07:32:21 pm »
I would like to be able to zoom like in googlemaps, meaning that the mouse
cursor does not only stay at the same screen coordinates while zooming, but
also on the same map coordinates.

The relevant code in the event handling section looks somewhat like this:
Code: [Select]
178         case sf::Event::MouseWheelMoved:
179             {
186                 float zoom = event.mouseWheel.delta > 0 ? 0.5f : 2.f;
187                 sf::Vector2f newpos (window->getSize().x, window->getSize().y);
188                 newpos /= 2.f;
189                 newpos -= sf::Vector2f (sf::Mouse::getPosition(*window).x, sf::Mouse::getPosition(*window).y);
190                 newpos /= zoom;
191                 view.move (-newpos);
192                 view.zoom (zoom);
194                 break;
195             }

I played around with some of the parameters, but i can't get it to zoom towards
the mouse position. Any suggestions?

12
Graphics / How to sync a position from one View to another?
« on: August 08, 2011, 04:26:03 pm »
In my game, the player may zoom the view in and out. However, it is
possible, to zoom out far enough, that the unit's are'nt visible anymore
(they become too small).

Anyway, i want to have a dot on top of each unit, that does'nt change its
size when zooming. I created another view for that purpose, it is called
'overview'. When the default view changes its position, the overview gets the
new position as well:
Code: [Select]
overview.SetCenter (view.GetCenter ());
A zoom to the view is not applied to the overview.
The dot is created on the fly:
Code: [Select]
window->Draw (sf::Shape::Circle ((*unitIterator)->Position, 5.f, sf::Color::Green));

However, the dot is only on top of the unit, when the view is not zoomed.
When zooming out, the dot is not on top of the unit anymore. I kind of get
the idea, why this is so. But i have no idea, how to get the dot being on
top of the unit no matter what the zoom is.

Any suggestions?

13
Graphics / What happened to the Rotation of a Sprite?
« on: June 12, 2011, 07:34:45 pm »
After upgrading to SFML 2.0, i can't get my animating function working.

What it does is to move a Sprite to it's destination (Course) by turning first,
until the Sprite is rotated towards its destination, and then moving straight.

The turning doesn't work any more. Either it rotates, or it moves in the
wrong direction (depends on the condition, det is checked for; either > or <).

Code: [Select]
void
normalize (sf::Vector2f& v)
{
    v /= (float) sqrt (pow (v.x, 2) + pow (v.y, 2));
}

float
distance_pow_2 (const sf::Vector2f& v1, const sf::Vector2f& v2)
{
    return (float) pow (v2.x - v1.x, 2) + pow (v2.y - v1.y, 2);
}

void
Unit::Animate (float TimeSpan)
{
    if (Position == Course) return;

    float angle = atan2 (Course.y - Position.y, Course.x - Position.x) * 180.f / PI + 90.f;
    //float angle = atan2 (Position.x - Course.x, Position.y - Course.y) * 180.f / PI;
    if (angle < 0) angle += 360.f;

    //std::cout << "angle: " << angle << std::endl;

    float distance =  Speed * TimeSpan * 3.6;

    Rotation = Sprite.GetRotation ();
    //std::cout << "Rotation: " << Rotation << std::endl;

    if (abs (abs (angle) - abs (Rotation)) < 0.1) // move straight
    {
        if (pow (distance, 2) > distance_pow_2 (Course, Position))
        {
            Position = Course;
        }
        else
        {
            sf::Vector2f direction = Course - Position;
            normalize (direction);
            direction *= distance;
            Position += direction;
        }
    }
    else // turn
    {
        float turn = asin (distance / (2.f * Probs->TurningRadius)) * 180.f / PI;

        if (abs (abs (Rotation) - abs (angle)) < abs (turn))
        {
            Rotation = angle;
        }
        else
        {
            float x = sin (Rotation * PI / 180.f);
            float y = cos (Rotation * PI / 180.f);
            sf::Vector2f front (x, y);
            front += Position;

            // Sarros' Rule
            float det = front.x * Course.y + Position.x * front.y + Course.x * Position.y -
                Position.y * front.x - front.y * Course.x - Course.y * Position.x;

            Rotation += (det < 0) ? -turn : turn;
        }

        float x = sin (Rotation * PI / 180.f);
        float y = cos (Rotation * PI / 180.f);
        sf::Vector2f front (x, y);
        normalize (front);
        front *= distance;
        Position -= front;
    }
}


Position and Course are vector2f's, i hope the rest is clear.

After i got it working with SFML 1.6, i was hoping, i'll never have to fiddle with this code again.
I hate trigonometry...

14
General / Upgrading to SFML 2.0
« on: June 12, 2011, 07:12:39 pm »
After switchin to SFML 2.0, i stumbled over a few issues.
Some things where easy to fix, like Sprite::SetCenter doesn't exist any
more, now it's SetOrigin.

But it took me a while to figure out, that Clock::GetElapsedTime now
returns an int with milliseconds resolution, instead of a float with seconds
resolution.

Is there some sort of tutorial or a collection of issues to consider when
upgrading? I think at least things like the change of Clock::GetElapsedTime
should be communicated somehow...

edit:
And i'm a little confused about the comment on GetElapsedTime:
Quote
Its resolution depends on the underlying OS, but you can generally expect a 1 ms resolution.

Isn't it the purpose of SFML, *NOT* having to worry about the underlying OS?

15
Window / Why is RenderWindow::GetDefaultView () const in SFML2?
« on: June 11, 2011, 03:40:35 pm »
I have the following Code snippet:
Code: [Select]
       case sf::Event::Resized:
            {
                window->GetDefaultView ().SetSize (event.Size.Width, event.Size.Height);
                break;
            }
        case sf::Event::MouseWheelMoved:
            {
                // When zooming in, center view on Mouse Cursor Position
                if (event.MouseWheel.Delta > 0)
                {
                    window->GetDefaultView ().SetCenter (window->ConvertCoords (window->GetInput ().GetMouseX (), window->GetInput ().GetMouseY ()));
                    window->SetCursorPosition (window->GetWidth () / 2, window->GetHeight () / 2);
                }
                window->GetDefaultView ().Zoom (event.MouseWheel.Delta < 0 ? 0.5f : 2.f);
                break;
            }

And get the following errors for it:
Code: [Select]
GUI.cc:79:87: error: passing ‘const sf::View’ as ‘this’ argument of ‘void sf::View::SetSize(float, float)’ discards qualifiers [-fpermissive]
GUI.cc:88:148: error: passing ‘const sf::View’ as ‘this’ argument of ‘void sf::View::SetCenter(const Vector2f&)’ discards qualifiers [-fpermissive]
GUI.cc:91:88: error: passing ‘const sf::View’ as ‘this’ argument of ‘void sf::View::Zoom(float)’ discards qualifiers [-fpermissive]

That did work in SFML1.6. I think the problem is, that RenderWindow::GetDefaultView () became const in SFML2.
Now i would like to know why and maybe a suggestion, how to archieve what i want.

Pages: [1] 2
anything