Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: HELP! create and call sf::image and sf::sprite in other .cpp .h file  (Read 1288 times)

0 Members and 1 Guest are viewing this topic.

EN

  • Newbie
  • *
  • Posts: 2
    • View Profile
please help!! this is my code, how to create sf::sprite in other .cpp file.
here's my code:

Quote
Control.h
class myClass{
public:
   void Initialize();
   void LoadImage(sf::Sprite &sprite);
protected:   
private:
};

Quote
Controls.cpp
void myClass::Initialize()
{
   sf::Image image;
   sf::Sprite sprite;
}
void myClass::LoadImage(fs::Sprite &sprite)
{
   image.LoadFromFile("Player.png");
   sprite.SetImage(image);
}

Quote
main.cpp
int main()
{
Controls obj;
obj.LoadImage(sprite);
}

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: HELP! create and call sf::image and sf::sprite in other .cpp .h file
« Reply #1 on: February 24, 2013, 12:58:43 pm »
sprite doesn't exist in main.cpp
In myClass::Initialize, image and sprite are useless and destructed at the end of the method
In myClass::LoadImage you use fs instead of sf, and image doesn't exist

This is really bad, you should learn a little more C++ before. :-\

EN

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: HELP! create and call sf::image and sf::sprite in other .cpp .h file
« Reply #2 on: February 24, 2013, 01:10:54 pm »
I want my sf::image,sprite to do in other .cpp file and I dont want it to call in main.cpp.
what should I do? that's not fs its sf, sorry that is my 1st post.

do i need to declare sf::Image, and Sprite inside public class?

Thanks.
« Last Edit: February 24, 2013, 01:24:37 pm by EN »

 

anything