SFML community forums

Help => General => Topic started by: dan185 on November 13, 2013, 04:15:22 am

Title: How to declare a shape in a header
Post by: dan185 on November 13, 2013, 04:15:22 am
Can someone give me a dumbed down example of how to declare a function in a header that declares a certain shape based on parameters passed to it? One that can declare multiple shapes by calling it multiple times?
Title: Re: How to declare a shape in a header
Post by: Nexus on November 13, 2013, 07:40:33 am
CreateShape.hpp
#ifndef CREATESHAPE_HPP
#define CREATESHAPE_HPP

sf::ConvexShape createShape(const sf::Color& color);

#endif

CreateShape.cpp
#include "CreateShape.hpp"

sf::ConvexShape createShape(const sf::Color& color)
{
    sf::ConvexShape shape;
    shape.setFillColor(color);
    ...
    return shape;
}

But that's basic C++ knowledge. You should really learn the language before using SFML, or you will constantly get stuck at minor tasks, which is very frustrating...