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

Pages: [1]
1
Graphics / Centralising a sf::Text inside a sf::Rectangle
« on: December 18, 2019, 04:33:31 pm »
So i have my function that puts an object into the center of the screen.

Quote
    object.setPosition(width,height);
    sf::FloatRect shapeRectangle = object.getLocalBounds();
    object.setOrigin(shapeRectangle.left + shapeRectangle.width/2.0f,
                    shapeRectangle.top  + shapeRectangle.height/2.0f);

The function is called twice once for an sf::RectangleShape and another for a sf::Text that should appear inside the sf::RectangleShape.  This works great if I call the function above after i have called sf::Texts function setString().

However if i put the object in the center of the screen and then call setString() or if setString(" "). Then the text that i put in using setString() is slightly offset. It goes up and to the right instead of the center of the sf::RectangleShape.

Not really sure how to solve this. :<

2
Graphics / Re: Does setScale() affect setPostion() and setOrigin()?
« on: December 16, 2019, 11:54:39 am »
The issue seems to have been that the top of the sf::Sprite was set to the center of the screen. So if i subtracted the sprites height / 2 from the height that i passed into setPosition() and setOrigin() then the actual center of sf::Sprite was in the center of the screen rather than the top of the sf::Sprite

3
Graphics / Does setScale() affect setPostion() and setOrigin()?
« on: December 16, 2019, 09:07:47 am »
I'm trying to write a generic function for bringing an object on the center of the screen. Works great for sf::RectangleShape , sf::Text. However when i try to do it on a sf::Sprite the sprite seems to position itself closer to the bottom of the screen rather than the middle. The only differenace is that i downscale the sf::Sprite with setScale(sf::Vector2f(0.20,0.20)). So i'm wondering does this affect the setPoistion() and setOrigin of a sf::Sprite? Or is there some other reason the sf::Sprite seems to be going towards the bottom of the screen rather than center.

The code to put a sf::sprite at the center of screen is as seen below.

Quote
sf::Vector2u windowCoords = window.getSize();

float width = windowCoords.x / 2.0f;
float height = windowCoords.y / 2.0f;

sprite.setPosition(width,height);

sf::FloatRect shapeRectangle = sprite.getLocalBounds();

sprite.setOrigin(shapeRectangle.left + shapeRectangle.width/2.0f,
shapeRectangle.top  + shapeRectangle.height/2.0f);




4
So i'm developing a simple graphical Sudoku game. As most application I have the standard loop

Quote
    while (window.isOpen()){
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                window.close();
            if(menuChoice == 0) {
                menuChoice = mainMenu.handleEvents(event, window);
            }
        window.clear();
        if(menuChoice == 0) {
            mainMenu.drawMainMenu(window);
        }

As you'll notice from the code sample above i have two if statement if menuChoice == 0 The first decide what to draw based on the users choice in the main menu. The second says to draw the main menu if the user has not chosen any option yet.

Is there any good way of getting rid of this double if structure and still achieve the same goal?

5
Graphics / Following the RAII idiom with textures.
« on: December 08, 2019, 09:07:19 pm »
Hi i've recently been reading about some C++ idioms and i'm having a bit of trouble understanding how to follow RAII with for example textures in SFML. My main concern comes from the loadFromFile() function for textures.

Say I want to create a menu with a nice background then(as I understand it) I will first have to instantiate my menu object then load a texture from file. Am I correct in thinking this does not follow RAII? if i'm missing something here I would love some insight.

6
Graphics / What is the best way to handle interactive grid?
« on: December 04, 2019, 08:55:29 pm »
I'm in the planning phase of doing a Sudoku. Should i move all 81 shapes individually or is there a better way?

Pages: [1]
anything