HAving the white square problem, but can figure out where the issue exactly is.
TextureManager.h
#pragma once
#include <SFML\Graphics.hpp>
class TextureManager
{
public:
TextureManager(void);
~TextureManager(void);
sf::Texture getTexture(int id);
void InitTextures();
private:
sf::Texture textureArray[20];
};
TextureManager.cpp
#include "TextureManager.h"
using namespace std;
TextureManager::TextureManager(void)
{
}
TextureManager::~TextureManager(void)
{
}
void TextureManager::InitTextures()
{
printf("Starting texture loading process \n");
textureArray[0].loadFromFile("data/graphics/map/grassTile.jpg"); // 0
textureArray[1].loadFromFile("data/graphics/map/mountainTile.png");
printf("Texture Loading ended! \n");
}
sf::Texture TextureManager::getTexture(int id)
{
return textureArray[id];
}
SpriteManager.h
#pragma once
#include <SFML\Graphics.hpp>
#include "TextureManager.h"
class SpriteManager
{
public:
TextureManager texManager;
sf::Sprite getSprite(int id);
SpriteManager(TextureManager tm);
~SpriteManager(void);
private:
sf::Sprite spriteArray[20];
void initSprites();
};
SpriteManager.cpp
#include "SpriteManager.h"
using namespace std;
SpriteManager::SpriteManager(TextureManager tm):texManager(tm)
{
texManager.InitTextures();
initSprites();
}
SpriteManager::~SpriteManager(void)
{
}
void SpriteManager::initSprites()
{
printf("Started loading sprites! \n");
spriteArray[0].setTexture(texManager.getTexture(0)); //0
spriteArray[1].setTexture(texManager.getTexture(1));
printf("Sprite loading complete! \n");
}
sf::Sprite SpriteManager::getSprite(int id)
{
return spriteArray[id];
}
main.cpp
#include <SFML\Graphics.hpp>
#include <conio.h>
#include "SpriteManager.h"
int main()
{
printf("Starting game \n");
TextureManager texManager;
SpriteManager spriteManager(texManager);
sf::RenderWindow window(sf::VideoMode(800,600),"NeverLand");
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type==sf::Event::Closed)
{
window.close();
}
}
window.clear();
window.draw(spriteManager.getSprite(0));
window.display();
}
return 0;
}
Can anyone figure out where exactly do I lose the texture and what to do to avoid it?