I have a program that simply loads and displays an image in a window. I made the same program with all the code inside the main method and I had no problems with loading time. However, now that I've separated some parts into objects, the loading time for the image is at least 5 seconds. Before, it took less than a second. I just need some advice as to how to get this thing to load faster. Thanks.
07.cpp
#include <SFML/Graphics.hpp>
#include "07.h"
int main() {
sf::RenderWindow window(sf::VideoMode(800,600), "Objects");
window.setFramerateLimit(45);
sf::Event e;
sf::Image p;
p.loadFromFile("Bird.png");
Bird b(p);
sf::Texture tex;
sf::Sprite sprite;
tex.loadFromImage(b.getImage());
sprite.setTexture(tex);
while(window.isOpen()) {
if(window.pollEvent(e) && e.type == sf::Event::Closed) window.close();
window.clear(sf::Color::Black);
window.draw(sprite);
window.display();
}
}
07 - Bird.cpp
#include "07.h"
sf::Image image;
Bird::Bird(sf::Image i) {
image = i;
}
sf::Image Bird::getImage(){
return image;
}
07.h
#ifndef BIRD_H
#define BIRD_H
#include <SFML/Graphics.hpp>
class Bird {
public:
Bird(sf::Image i);
sf::Image getImage();
};
#endif