First you need a default constructor.
Tank() {}
You can't create object of a class with only copy constructor. Also instead of sf::Image (which is used for pixel manipulation) use
sf::Texture
. To draw a sprite you will need a sf::Sprite object which will contain reference to the texture loaded from file.
sf::Sprite mySprite(myTexture);
Unlike textures, sprites can be drawn on window. You must also set position of sprite with
mySprite.setPosition((float)x, (float)y);
. x and y are pixel coordinates, where 0,0 is upper left corner and (on your Window) 800, 600 bottom right corner.
Also, you must not forget to clear the window from artifacts before drawing and displaying:
1 2 3
|
Window.clear();
Window.draw(mySprite);
Window.display();
|
Ofcourse, to prevent program from instantly closing, you will need a loop which will keep redrawing window content untill, say, key is pressed:
So that should look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
sf::Texture myTexture;
myTexture.loadFromFile("myFile.png");
sf::Sprite mySprite(myTexture);
mySprite.setPosition(400, 300);
sf::Event Event;
while(Window.isOpen())
{
while(Window.pollEvent(Event))
{
if(Event.type == sf::Event::KeyPressed)
{
Window.close();
}
}
Window.clear();
Window.draw(mySprite);
Window.display();
}
|