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

Pages: [1]
1
Many thanks! It works now, though I still cannot work out why.

2
Thanks, here's the class definition:
struct Position
{
        float x;
        float y;

        Position(float x = 0.f, float y = 0.f) : x(x), y(y)
        {
        }
};

class SquareComponent : public sf::RectangleShape
{
private:
        Position loc;

public:
        const float SideLen = 10.f;
        SquareComponent(Position position = {});
        void setLoc(Position position = {});
};

SquareComponent::SquareComponent(Position position) : RectangleShape(sf::Vector2f(SideLen, SideLen)), loc(position)
{
        setPosition(loc.x, loc.y);
        setFillColor(sf::Color::White);
}

void SquareComponent::setLoc(Position position)
{
        loc = position;
        setPosition(loc.x, loc.y);
}
And I used the built-in shapes (CircleShape, etc.) last time I tried SFML.

3
Hello, I'm new to SFML (and C++, I'm a first-year university student). I defined a custom shape outside of the main loop and it wouldn't draw. But, when I define that inside the loop, it works very well.
What's wrong?
(SquareComponent is something I defined myself. I have tried SFML before, but everything was OK that time.)

int main(void)
{
        sf::RenderWindow window(sf::VideoMode(WindowWidth, WindowHeight), "SFML", sf::Style::Close | sf::Style::Titlebar);

        // SquareComponent thing1({14.f,11.f});

        while (window.isOpen())
        {
                sf::Event event;

                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }

                window.clear(sf::Color::Black);

                SquareComponent thing1({14.f,11.f}); // if defined outside this loop (line 31), it won't draw!
                window.draw(thing1);
               
                window.display();
        }
}

Pages: [1]
anything