SFML - C++, sprite not displaying

Im trying to practice with sfml, but it's not working out to well. I created a class to handle the image and sprite for my "Tank" which i am trying to display. When i run the program i get no errors, the window pops up as normally but nothing is displayed.... Any help would be greatly appreciated.

Tank.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef TANK_H
#define TANK_H
#include <string>
#include <SFML/Graphics.hpp>

class Tank
{
    public:
        Tank();
        Tank(const Tank& Copy);
        bool LoadFile(const std::string ImageFile); //loads image
        sf::Sprite DrawFile(Tank& Copy); //function returns sprite for main
        //loop in main can draw using this function
    protected:
    private:
        static sf::Image Image; //same image for all tanks
        sf::Sprite Sprite;
};

#endif // TANK_H 

Tank.cpp
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
#include "Tank.h"
#include <iostream>
#include <SFML/Graphics.hpp>
#include <string>
sf::Image Tank::Image;
Tank::Tank(){

}
Tank::Tank(const Tank& Copy):
    Sprite(Copy.Sprite)
    {
        Sprite.SetImage(Image); //set the image

    }



bool Tank::LoadFile(const std::string ImageFile)
{
    if(!Image.LoadFromFile(ImageFile))
    {
        return false; //used in main to terminate program if false
    }
    return true;
}

sf::Sprite Tank::DrawFile(Tank& Copy) //return the sprite
{
    return Copy.Sprite;
}

main.cpp
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
#include <iostream>
#include "Tank.h"
#include <SFML/Graphics.hpp>
class Tank; //compile Tank first

int main()
{
   sf::RenderWindow Window(sf::VideoMode(800,600,32), "TANKWARS");
   Tank Copy;
   Tank Playerone(Copy);
   if(!Playerone.LoadFile("Tank1.tga"))
   {
       return EXIT_FAILURE; //end if file cannot be loaded
   }
   while(Window.IsOpened())
   {
       sf::Event Event;
       while(Window.GetEvent(Event))
       {
           if(Event.Type == sf::Event::Closed)
            Window.Close(); //close if X is hit
       }
       Window.Clear(); //clear
       Window.Draw(Playerone.DrawFile(Playerone)); //use function to return
       //the sprite
       Window.Display(); //display contents
   }
   return EXIT_SUCCESS;
}
You don't seem to be good with classes yet. The problem is that you never set Sprite to whatever you loaded in Tank::LoadFile.

In general a class is a blueprint for an object. Your object is a Tank. It contains a Sprite, it can be loaded and drawn. Methods load and draw are made part of the class so that they can work with Sprite. Load should create a new sprite and assign it to Sprite. Draw should do Window.Draw(Sprite); Window could be passed as a parameter.
Thanks for the input, i feel i need to immerse myself further into c++ before i can start learning more complex things like SFML. I have basic understanding of classes and most syntax, but i fall off in more complex programs because of lack of experience with programs.
Topic archived. No new replies allowed.