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

Pages: [1] 2 3 4
1
Graphics / Re: origin relative to the Transformable
« on: September 06, 2024, 12:50:26 am »
Quote
The origin of a drawable should always be updated whenever the drawable is manipulated unless you can be sure that it doesn't need it for some reason. This is particularly important with texts that change string, fonts, styles, sizes etc..

I was proposing for SFML to handle this. Thus, when I set the origin of a text to its center, then update the string in the text, I wouldn't have to worry about updating the origin as well. Not a trivial thing, if this functionality is to be introduced to all Drawables...

2
Graphics / How to deal with textures in an animation?
« on: September 05, 2024, 11:54:05 pm »
I want to play animations that simply consist of images that should be updated after some delay. I see several ways to do this, but am uncertain if there is a preferred one.

Option 1:

I load all images of the animation into a texture each. During the animation I update the sprite with the correct texture.

One drawback I can think of is that I have a lot images in the graphics card memory that aren't currently drawn.

Option 2:

I have only one texture and update its pixels for each frame during the animation.

I think it was said that copying pixels to graphics memory is a costly operation. Does this outweight wasting lots of graphics memory with data currently not on screen?

Option 3:

I have a tilemap for the animation. Thus a single image with all the frames for the animation side by side. During the animation I update the rectangle of the sprite to where points to in the texture. This is just a variation of Option 1 I think.

Is there a general consensus that one is preffered over the other?

3
Graphics / Re: origin relative to the Transformable
« on: August 27, 2024, 07:42:14 pm »
I agree that the function itself would be trivial. However, when the Transformable is meant to preserve the relative origin (as in my example with setting a new string to the Text) it gets a bit trickier.

But if it doesn't fit with the rest of the API I have to accept that.

4
Graphics / Re: origin relative to the Transformable
« on: August 26, 2024, 09:01:56 pm »
Quote
I don't see us adding setRelativeOrigin

What do you mean by that? You're not willing to invest into the developement of that function? Or you wouldn't want that to be part of the API?

I'm asking as I might consider developing this function myself at some point; and, if that's appreciated, contribute it to SFML.

5
Graphics / origin relative to the Transformable
« on: August 26, 2024, 01:08:43 am »
I would like to set the origin of a Transformable to its center. So far I'm doing it like this:

text.setOrigin(text.getLocalBounds().width / 2, text.getLocalBounds().height / 2);

That's quite verbose I think. Moreover, once I set a new string to be displayed, I also need to calculate the origin again.

Instead, I would like to do something simple like: setRelativeOrigin(.5f, .5f) (with 0, 0 being top left; 1, 1 being lower right, and thus the center at 0.5, 0.5.)

Is something like this already possible and I've missed it? Otherwise I'd like to request it as a feature :)

6
Ups my bad. I just realized that I'm still on SFML 2.5.1. Accoding to the changelog, the missing function was introduced in 2.6

7
From this code

sprite.getGlobalBounds().getPosition()

I get this error:

error: ‘sf::FloatRect’ {aka ‘class sf::Rect<float>’} has no member named ‘getPosition’
   26 |         info.setPosition(image->sprite.getGlobalBounds().getPosition());
      |                                                          ^~~~~~~~~~~


Accoding to the documentation Rect does have a member getPosition: https://www.sfml-dev.org/documentation/2.6.1/classsf_1_1Rect.php

What am I missing?

8
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?

9
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.

10
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?

11
Ok, I decided to add that portion to the background to give the text a little frame:

sf::FloatRect bounds = text.getLocalBounds();
sf::Vector2f size(bounds.left * 2 + bounds.width, bounds.top * 2 + bounds.height);
sf::RectangleShape background(size);

Just out of curiosity, what is the reason for there being a hidden offset in sf::Text?

12
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?

13
Window / Re: How to select a Sprite from Mouse position?
« on: June 26, 2020, 09:01:22 pm »
Thanks for the hint to Window::mapPixelToCoords().

I did use getGlobalBounds on the Sprites, but upon further investigation I realized that the Sprites I had drawn and the Sprites I called getGlobalBounds on were not the same instances. I'm using pointers now and all is good!

14
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?

15
Graphics / Re: How to move the View?
« on: June 20, 2020, 12:57:17 am »
Thanks, especially for the link to the tutorial. That was very helpful.

Pages: [1] 2 3 4