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

Pages: [1]
1
I'm going to completely rethink some feature implementations because I don't think I can fix this bug. Thank you for helping, I very appreciate it!

2
I'm very sorry I know what is a template or method overloading, but I don't know how to implement this. It would been easier if std::variant<v1, v2> returned exactly v1 or v2, not std::variant. So for example how do I implement method overloading if I have only one type? (ExportedSFMLObject). I'm sorry I don't understand

3
I mean getType function should return SFML drawable class:
??? getType(ExportableSFMLObject obj) {
    if (std::holds_alternative<sf::RectangleShape>(obj))
        ; // it is an sf::RectangleShape
        // return sf::RectangleShape
    else if (std::holds_alternative<sf::CircleShape>(obj))
        ; // it is an sf::CircleShape
        // return sf::CircleShape
    else if (std::holds_alternative<sf::Text>(obj))
        ; // it is an sf::Text
        // etc
    else if (std::holds_alternative<sf::Sprite>(obj))
        ; // it is an sf::Sprite
    else if (std::holds_alternative<int>(obj))
        ; // it is an sf::int
}
 

4
I think its going to work! But is it possible to contain type resolving code in function? Or like I said it's impossible because there is no exact type?

5
It's the main problem in my project

6
Basically I have function that generates SFML object from LevelObject (template). i.e
void draw(LevelObject obj, sf::RenderWindow &window) {
    if(obj.type == RECTANGLE) {
         sf::RectangleShape rect(obj.width, obj.height);

        window.draw(rect);
    } // other types
}
 

So now I'd like to return generated sfml object, for future export object properties to file, and later load them. Also later I'd like to create vector that will contain all loaded objects from file, but the same problem remains. What vector type should I have? I tried std::variant:
using ExportableSFMLObject = std::variant<sf::RectangleShape, sf::CircleShape, sf::Text, sf::Sprite, int>;

ExportableSFMLObject function(...) { ... }
 

But then I couldn't figure out exactly what type function returns, maybe it's RectangleShape, or sf::CircleShape. Even if I could resolve what type function returns, function GetType, where'd I'd like to realize type resolving, is also doesn't have exact type to return.

7
General / What type to set if I want to return SFML drawable objects?
« on: August 27, 2023, 07:15:56 pm »
Hello everyone!  :) I have a question. I'm new to C++ and SFML. How can I return any drawable object in one type? i.e:
// what type?
sfml_drawable? function(int x) {
    if(x == 1) {
        sf::RectangleShape rect(some_args);

        return rect;
    } else if(x == 2) {
        sf::CircleShape circl(some_args);

        return circl;
    }
}

function(1) // => sf::RectangleShape
function(2) // => sf::CircleShape
 

Please help me :P

Pages: [1]
anything