Hello everyone,
I have been playing around with SFML for a game I am designing, but I came across a problem, of which I am unable to determine if it is the result of just my poor coding or if SFML is designed to be called a different way.
Currently, I have a class called Module and it is a container for some variables and a Sprite.
class Module {
public:
sf::Sprite s_module;
std::vector<Module> children;
void addModule();
void moveFromSpeed(float, float);
void drawAll(sf::RenderWindow &);
void setImage(sf::Image & i_module);
};
Here are the methods
void Module::drawAll(sf::RenderWindow & App) {
cout << "Drawing Self\t" << children.size() << " Children" << endl;
App.Draw(s_module);
cout << "Drawing Children" << endl;
for (int i = 0; i < (int)children.size(); i++) {
children[i].drawAll(App);
}
}
void Module::addModule() {
children.push_back(Module());
}
void Module::setImage(sf::Image & i_module) {
//Set Sprite
s_module.SetImage(i_module);
s_module.SetBlendMode(sf::Blend::Alpha);
s_module.SetPosition(x, y);
}
void Module::moveFromSpeed(float tvelx, float tvely) {
//Uses the speed variables to move the ship
x += tvelx;
y += tvely;
s_module.SetPosition(x,y);
for (int i = 0; i < (int)children.size(); i++) {
children[i].moveFromSpeed(tvelx, tvely);
}
}
When I add Module classes to children, it slows down considerably. Around 30 children, it slows to maybe 5-10 fps.
Input is appreciated.
Thanks