Hey guys!
Been working on my small game recently and have hit a wierd issue.. When I load a texture over a certain size (256x256) the game drops to about 3 frames per second.. if I don't load it, the frames go back to 60..
I am using a Graphics singleton that has a function that loads my textures, and stores them in a vector list which can be called from anywhere to access the textures to set them in sprites
std::vector <sf::Texture*> mTextureList;
void GraphicsManager::CreateTexture(const char* filename)
{
sf::Texture* mTexture = new sf::Texture();
if(!mTexture->loadFromFile(filename))
std::cout << "Error loading texture: " + (char)filename << std::endl;
this->GetTextureList().push_back(mTexture);
}
std::vector<sf::Texture*>& GraphicsManager::GetTextureList()
{
return mTextureList;
}
I load all the textures in my GameEngine Init function as seen below
The texture causing the slow down is background1
void GameEngine::Init(const char* iTitle, int iWidth, int iHeight, bool iFullscreen)
{
Graphics->InitWindow(iTitle, iWidth, iHeight, iFullscreen);
m_running = true;
Graphics->CreateTexture("survivor1.png");
Graphics->CreateTexture("zombienormal.png");
Graphics->CreateTexture("bullet.png");
Graphics->CreateTexture("background1.png"); // < LARGE TEXTURE
printf("GameEngine Init\n");
}
and I set textures to sprites like this (I know its not the perfect way but I want to work out why this is happening first)
this->GetSprite().setTexture( *Graphics->GetTextureList()[1] );
Anyone know why this massive slowdown is happening?
I have tried changing the texture etc, but any texture > then around 256x256 smashes performance.
WIERD THING.. I tried using the CPU Performance tester under Analyze > Launch Performance Wizard and this fixes everthing.. it stops the slowdown completely.. but if I run it without this.. the slowdown occurs..
Also - I am not even using the background texture, I am just loading it and it is causing the problem.. I am passing my stuff as reference.. so I am sure I am not making a copy of the texture when I get the texture list, so I don't know why this massive frame drops happening.
what the hell is going on?
Please help guys!
Thanks