Making sf::Sprite a member of a class.

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#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.
Last edited on
sf::Sprite entsprite();

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 !
Topic archived. No new replies allowed.