Hi everyone!
I followed those posts, and that helped me a lot, but when I try to draw a instance of my class, derived from sf::Sprite, it appears black on the screen, with no error listed...
I tried many things, being quite a beginner, but nothing seems to work...
My image manager is working, thanks to one of the tutorials on this site, because spriteMenuDebutPetit is correctly displayed and there's no error log in the console.
Could anyone help me?
Here is my class header:
#include <string>
#include <SFML/Graphics.hpp>
#include "ImageManager.h"
class InterfaceElement : public sf::Sprite
{
public:
InterfaceElement (const std::string& imageToLoad, int positionX, int positionY, ImageManager ImageManager);
InterfaceElement::~InterfaceElement ();
void draw (sf::RenderWindow* window);
private:
sf::Sprite m_sprite;
};
my class .cpp:
#include <SFML/Graphics.hpp>
#include <map>
#include <string>
#include <iostream>
#include "InterfaceElement.h"
#include "ImageManager.h"
InterfaceElement::InterfaceElement ( const std::string& imageToLoad, int positionX, int positionY, ImageManager imageManager)
{
sf::Sprite m_sprite;
m_sprite.setTexture (imageManager.getTexture (imageToLoad) ) ;
m_sprite.setPosition (positionX, positionY);
}
InterfaceElement::~InterfaceElement ()
{
}
void InterfaceElement::draw (sf::RenderWindow* window)
{
window->draw (m_sprite);
}
and my main.cpp:
#include <SFML/Graphics.hpp>
#include "ImageManager.h"
#include "InterfaceElement.h"
int main ()
{
sf::RenderWindow Window (sf::VideoMode (1024, 640), "", sf::Style::Titlebar | sf::Style::Close);
ImageManager imageManager;
InterfaceElement background ("ressources/menu/fond_menu_lancement.png", 0, 0, imageManager);
sf::Sprite spriteMenuDebutPetit;
spriteMenuDebutPetit.setTexture (imageManager.getTexture ("ressources/menu/menu_debut_petit.png") );
spriteMenuDebutPetit.setPosition ((1024/2-384/2), (640-384));
InterfaceElement secondMenu ("ressources/menu/pwned-DH.jpg", (1024/2 - 384/2), (640-384), imageManager);
while (Window.isOpen())
{
sf::Event Event;
while (Window.pollEvent (Event) )
{
switch (Event.type)
{
case sf::Event::Closed:
Window.close();
break;
default:
break;
}
}
background.draw (&Window);
Window.draw (spriteMenuDebutPetit);
Window.draw (secondMenu);
Window.display ();
}
return 0;
}