#ifndef TANK_H
#define TANK_H
#include <SFML/Graphics.hpp>
class Tank
{
public:
Tank(const Tank& Copy);
bool LoadFile(const std::string ImageFile);
protected:
private:
static sf::Image Image;
sf::Sprite Tank1;
};
#endif // TANK_H
#include "Tank.h"
#include <iostream>
#include <SFML/Graphics.hpp>
Tank::Tank(const Tank& Copy):
Image(Copy.Image),
Tank1(Copy.Tank1)
{
Tank1.SetImage(Image);
}
bool Tank::LoadFile(const std::string ImageFile)
{
if(!Image.LoadFromFile(ImageFile))
{
return 1;
}
return 0;
}
#include <iostream>
#include "Tank.h"
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow Window(sf::VideoMode(800,600,32), "TANKWARS");
Tank Playerone(/* ??? */); //im still confused on how to declare this!
if(!Playerone.LoadFile("Tank.tga"))
{
return EXIT_FAILURE;
}
}
int main()
{
sf::RenderWindow Window(sf::VideoMode(800,600,32), "TANKWARS");
Tank Playerone = Tank(); // calls default constructor to create a local instance
if(!Playerone.LoadFile("Tank.tga"))
return EXIT_FAILURE;
}
i have no clue what to put in for the parameter
J:\SFML\SFML_SmallGame\main.cpp||In function 'int main()':|
J:\SFML\SFML_SmallGame\main.cpp|9|error: no matching function for call to 'Tank::Tank()'|
J:\SFML\SFML_SmallGame\Tank.h|8|note: candidates are: Tank::Tank(const Tank&)|
||=== Build finished: 1 errors, 0 warnings ===|
You must define a default constructor too; currently you can only create Tank instances by copying other instances.
Hmm... Don't you think you should learn C++ first? :P
Problem now is its telling me there is an undefined reference to sf::Image, most likely me just missing something obvious. Thanks for the helpThe undefined reference means there is a linking problem. You want to make sure you are linking the correct SFML library files in the linker options of whatever IDE you're using. Check out the Getting Started tutorials for how to set up the libs.
Problem now is its telling me there is an undefined reference to sf::ImageGoogle "C++ static member" ;)