Hello everyone,
I'm new in this forum and I got some problem with sf::Sprite. I'm trying to do a class called piece and one of his attributes is a sprite and a texture. This is the code I wrote in the class Piece.h.
#ifndef PIECE_H_
#define PIECE_H_
class Piece {
public:
Piece();
virtual ~Piece();
sf::Texture p_texture;
sf::Sprite p_sprite;
};
#endif /* PIECE_H_ */
And this is Piece.cpp
#include <SFML/Graphics.hpp>
#include <iostream>
#include "Piece.h"
using namespace std;
Piece::Piece() {
if(!p_texture.loadFromFile("./Images/Pieza_Azul.png"))
{
cout << "Error." << endl;
}
p_sprite.setTexture(p_texture,true);
}
Piece::~Piece() {
// TODO Auto-generated destructor stub
}
And this is the main.cpp
#include <SFML/Graphics.hpp>
#include "Pieces/Piece.h"
#include <iostream>
using namespace std;
int main() {
Piece obj_piece;
// Create the main window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML");
window.setVerticalSyncEnabled(true);
window.setFramerateLimit(60);
// Start the game loop
while (window.isOpen())
{
// Process events
sf::Event event;
while (window.pollEvent(event))
{
// Close window : exit
if (event.type == sf::Event::Closed)
window.close();
}
// Clear screen
window.clear(sf::Color::White);
window.draw(obj_piece.p_sprite);
// Update the window
window.display();
}
return 0;
}
When I start to compile the program, does not give any error during the compilation process, but when I try to run get an error:
not valid domains REMAIN!
In addition, the window look really weird things.
I wanted to comment if you can put a sprite in a class, I've tried in various ways, but it still fails. When I put a Sprite in a class and compile SFML window disappears instantly, and gives no errors in compilation or execution.
The question is, you should put a sprite in a class such as a character in order to have the sprite associated with that object? If yes the attribute must be private right?
regards
Yemlhalf
ps: Sorry if I made grammatical or lexical errors I have to improve my English: p