SFML community forums

Help => Graphics => Topic started by: kapesu8 on May 05, 2012, 06:08:37 pm

Title: shape.setTexture() problems
Post by: kapesu8 on May 05, 2012, 06:08:37 pm
With this,

        sf::RectangleShape rect = sf::RectangleShape::RectangleShape(sf::Vector2f(13,31.2));
        rect.setFillColor(sf::Color::Blue);
        rect.setPosition(100,100);
        rect.setOrigin(rect.getSize().x/2,rect.getSize().y/2);
        rect.setTexture(sf::Texture::loadFromFile("car.png")); //error line

I got error,


Quote
   1   IntelliSense: a nonstatic member reference must be relative to a specific object   c:\users\kape\documents\visual studio 2010\projects\sfmlproject\sfmlproject\main.cpp   15   sfmlproject   18


I'm using SFML 2.0 dynamically linked one.
Title: Re: shape.setTexture() problems
Post by: victorlevasseur on May 05, 2012, 06:13:41 pm
sf::Texture::loadFromFile("car.png")
loadFromFile is not a static method.
You need to instanciate a sf::Texture, then use loadFromFile and pass it to setTexture.
Title: Re: shape.setTexture() problems
Post by: Laurent on May 05, 2012, 06:16:59 pm
Why don't you read the doc? :)
Title: Re: shape.setTexture() problems
Post by: kapesu8 on May 05, 2012, 06:20:30 pm
Where does it say all this :/?
Title: Re: shape.setTexture() problems
Post by: Laurent on May 05, 2012, 06:40:25 pm
On the sf::Texture page, and even on the main page... There are examples of calls to loadFromFile everywhere.

PS: you should also read the doc of shape classes
Title: Re: shape.setTexture() problems
Post by: kapesu8 on May 05, 2012, 07:24:23 pm
        sf::Texture texture;
        if(!texture.loadFromFile("car.png")){
                return EXIT_FAILURE;
        }
        rect.setFillColor(sf::Color::Blue);
        rect.setPosition(100,100);
        rect.setOrigin(rect.getSize().x/2,rect.getSize().y/2);
        rect.setTexture(texture);


   1   IntelliSense: no suitable conversion function from "sf::Texture" to "const sf::Texture *" exists   c:\users\kape\documents\visual studio 2010\projects\sfmlproject\sfmlproject\main.cpp   20   sfmlproject   18


The example on main page was about sprites right?
Title: Re: shape.setTexture() problems
Post by: kapesu8 on May 05, 2012, 09:10:42 pm
Inactive or ignoring this?
Title: Re: shape.setTexture() problems
Post by: Laurent on May 05, 2012, 10:34:22 pm
The prototype of the setTexture function is in the documentation. And the compiler message is self-explanatory anyway.

Seriously, is it too complicated to find this kind of information? Or are you just lazy? :P
Title: Re: shape.setTexture() problems
Post by: kapesu8 on May 05, 2012, 11:28:19 pm
I'm probably too lazy but could you just tell me why that doesn't work?
Title: Re: shape.setTexture() problems
Post by: Vovosunt on May 06, 2012, 12:07:16 am
This isn't even an SFML problem.... *facepalm*
Ever heard of pointers and references?  ::)
Title: Re: shape.setTexture() problems
Post by: kapesu8 on May 06, 2012, 12:11:11 am
I've tried to make const one but it didn't work either..
I only found one example about sf::Texture::loadFromFile duh
Title: Re: shape.setTexture() problems
Post by: Laurent on May 06, 2012, 09:24:37 am
Hmm then I strongly suggest that you learn C++ first. I'm not being rude, just trying to be helpful: you will have a hard time trying to use SFML (or any library) if you don't learn the basis of C++ first.
Title: Re: shape.setTexture() problems
Post by: kapesu8 on May 06, 2012, 10:51:21 am
Am I supposed to do it like
sf::Texture *texture
?
Title: Re: shape.setTexture() problems
Post by: Nexus on May 06, 2012, 11:27:58 am
No.

Really, take your time to read a good C++ book like the C++ primer. Don't read internet tutorials, most of them don't teach C++ correctly.

Attempting to use SFML like this is a waste of time, you'll get stuck again and again. The usage of pointers is a very basic topic, and it can't be explained in two sentences. Even if we answer this specific question for you, the next problem is sure to come soon.
Title: Re: shape.setTexture() problems
Post by: kapesu8 on May 06, 2012, 12:11:51 pm
Oh.. It was just..
  rect.setTexture(&texture);

Yeah I'm total newbie with C++ :P