-
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,
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.
-
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.
-
Why don't you read the doc? :)
-
Where does it say all this :/?
-
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
-
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?
-
Inactive or ignoring this?
-
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
-
I'm probably too lazy but could you just tell me why that doesn't work?
-
This isn't even an SFML problem.... *facepalm*
Ever heard of pointers and references? ::)
-
I've tried to make const one but it didn't work either..
I only found one example about sf::Texture::loadFromFile duh
-
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.
-
Am I supposed to do it like
sf::Texture *texture
?
-
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.
-
Oh.. It was just..
rect.setTexture(&texture);
Yeah I'm total newbie with C++ :P