SFML community forums
Help => General => Topic started by: beginner88 on December 24, 2008, 12:12:38 am
-
Hey :)
first at all, I´m new at programming and total new on programming with an API.
My first steps with SFML were very comfortable, it´s really easie to load some sprites, etc. But now I thought I could write the sf::Image, or sf::String function in a class, to make my source more clearly.
I read some post in the forum and came to a solution
class CSprite
{
public:
sf::String string;
virtual void Render(const sf::RenderWindow &Window) const
{
Window.Draw(string);
}
};
The main function
CSprite sprite;
And what now?
How should the render function look like?
sprite.Render(Window);
/* ??? */
And what is the best option to set the parameters?
Sorry for the many questions but I´ve never worked with an API befor and I spent a lot of time infront of my screen but I didn´t get a result :?
So are my ideas possible, or how would you handle this situation?
-
Is that class supposed to make sense or is it for learning purposes?
// Draws the CSprite using the Render function
window.Draw(sprite);
-
Of course that is possible, but I don't see the point in doing so.
sf::Sprite, sf::Image and all those are already separate classes.
Oh, and one more thing
the sf::RenderWindow-parameter cannot be const
void Render(sf::RenderWindow &Window) const
{
Window.Draw(string);
}
-
Thank you both!
@Wizzard: It´s just to practice how to use an API and C++ :)
@irri: Ok, but I thought when I get a class, for example, CPlayer with all his attributes like Health, Amor, etc. that I could use the sf::Image, sf::Sprite function in my class, to keep everything together... of course this is just an easy example and I know that it is more difficult in a "real" game.
// Draws the CSprite using the Render function
window.Draw(sprite);
If I would call this in the main function (while(Window.IsOpen())); I would try to render the instance of the CSprite class ( :?: ).
-
Thank you both!
@irri: Ok, but I thought when I get a class, for example, CPlayer with all his attributes like Health, Amor, etc. that I could use the sf::Image, sf::Sprite function in my class, to keep everything together... of course this is just an easy example and I know that it is more difficult in a "real" game.
Yeah, of course. But wouldn't it be easier to "Window.Draw(myCSprite.string);" in the main loop, if the sf::String in your class is public?
or, if your sf::string i private:
sf::String & GetString() const
{
return myString;
}
and then in the main loop Window.Draw(myCSprite.GetString());
they're just suggestions :P
-
Sorry that my answer comes quite late, but I used to spend the holidays with my familie and girlfriend :)
@irri: Ok, thanks for your suggestions, I think I´ll try it during the next few days...