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

Pages: [1]
1
Graphics / Calling draw(...) on instance of class implementing Drawable
« on: January 04, 2014, 02:00:32 am »
I noticed sf::Drawable's draw(...) method is protected. Why is that? (I'm not the best C++ programmer, so pardon me if the answer's rather obvious.)


As a followup question, what is the best way to call this method from outside my implementing class, StateMenu?

Here's my parent interface:
// a state the game can be in (menu, playing, credits).
class State : public EventHandler, public sf::Drawable {
public:
        virtual void update(const sf::Time &delta) = 0;
};

Here's an implementer of that interface:
// the title menu of the game.
class StateMenu : public State {
public:
        bool handleEvent(sf::Event &event);
        void update(const sf::Time &delta);
        void draw(sf::RenderTarget &target, sf::RenderStates states) const;
       
private:
        sf::Time mTimeElapsed;
};

And here's some snippets from main.cpp:
sf::RenderWindow window(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), TITLE,
                                                sf::Style::Titlebar | sf::Style::Close);
State *state;

void render() {
        window.clear(sf::Color::Black);
        state->draw(window, sf::RenderStates::Default);
        window.display();
}

int main() {
        ...
        state = new StateMenu;
        ...
        while (window.isOpen()) {
                ...
                render();
        }
        return 0;
}

Sorry if I posted too much code, and thanks in advance for any and all help!

Pages: [1]
anything