Hello, i'm trying to make a very simple game in SFML, and i have a problem.
Whenever i try to create sf::Sprite for the class where all properties of Player (his sprite, health, speed, etc.) It gives me error.
#include <sfml.h>
#include <list>
class Playerclass{
public:
int xspeed, yspeed;
float health;
sf::Sprite entsprite();
};
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Prince of Sandnigeria");
sf::Texture texture;
if (!texture.loadFromFile("texture.png"))
return EXIT_FAILURE;
//CREATE OBJECTS
Playerclass player;
player.entsprite.setTexture(texture);
player.health = 100;
sf::Font font;
if (!font.loadFromFile("arial.ttf"))
return EXIT_FAILURE;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(player.entsprite());
window.display();
}
return EXIT_SUCCESS;
}
The error is with player.entsprite.setTexture(texture) : "'player.Playerclass::entsprite' does not have class type"
I'd like to thanks in advance if anyone can give me a solution as to what am i doing wrong.
The () at the end implies that this is a function that will return a variable of sf::Sprite. Remove the () and it will be a variable of type sf::Sprite.
I can't believe, i were struggling along with a buddy on this long time, and never thought this would be the problem !
Thank you, i feel really silly right now !