官术网_书友最值得收藏!

Graduating to ravioli

Let's start small. Every game needs to have a window, and as you already know from of our window class will predictably look something like this:

class Window{
public:
    Window();
    Window(const std::string& l_title,const sf::Vector2u& l_size);
    ~Window();

    void BeginDraw(); // Clear the window.
    void EndDraw(); // Display the changes.

    void Update();

    bool IsDone();
    bool IsFullscreen();
    sf::Vector2u GetWindowSize();

    void ToggleFullscreen();

    void Draw(sf::Drawable& l_drawable);
private:
    void Setup(const std::string& l_title, const sf::Vector2u& l_size);
    void Destroy();
    void Create();

    sf::RenderWindow m_window;
    sf::Vector2u m_windowSize;
    std::string m_windowTitle;
    bool m_isDone;
    bool m_isFullscreen;
};

Because we want to handle setting up our window internally, the setup method is made private, as well as the destroy and create methods. Think of these as just helper methods that the user of this class doesn't need to know about. It's a good idea to keep certain information around after the setup is done, such as the window size or the title that's being displayed above it. Lastly, we keep around two Boolean variables to keep track of the window being closed and its state regarding full screen.

Tip

The naming convention that's being employed in our window class is referred to as the Hungarian notation. Using it is, of course, not required, but it can prove useful when dealing with lots of code, trying to track down bugs, and working in larger groups of people. We'll be utilizing it throughout this book. More information about it can be found here: http://en.wikipedia.org/wiki/Hungarian_notation

主站蜘蛛池模板: 保山市| 信宜市| 乌兰浩特市| 花莲县| 寿光市| 利川市| 武冈市| 隆德县| 克拉玛依市| 仪征市| 鄂温| 抚松县| 乐陵市| 奎屯市| 会宁县| 集安市| 衡水市| 西平县| 奇台县| 两当县| 兰溪市| 洞口县| 宜丰县| 孟津县| 辛集市| 东宁县| 海阳市| 抚州市| 颍上县| 翁源县| 古浪县| 扬中市| 万年县| 神农架林区| 镇宁| 望都县| 武鸣县| 维西| 白水县| 鄂托克旗| 榆林市|