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

Author Topic: shape.setTexture() problems  (Read 7074 times)

0 Members and 1 Guest are viewing this topic.

kapesu8

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
shape.setTexture() problems
« 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.
« Last Edit: May 05, 2012, 06:16:19 pm by Laurent »

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: shape.setTexture() problems
« Reply #1 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: shape.setTexture() problems
« Reply #2 on: May 05, 2012, 06:16:59 pm »
Why don't you read the doc? :)
Laurent Gomila - SFML developer

kapesu8

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: shape.setTexture() problems
« Reply #3 on: May 05, 2012, 06:20:30 pm »
Where does it say all this :/?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: shape.setTexture() problems
« Reply #4 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
Laurent Gomila - SFML developer

kapesu8

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: shape.setTexture() problems
« Reply #5 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?

kapesu8

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: shape.setTexture() problems
« Reply #6 on: May 05, 2012, 09:10:42 pm »
Inactive or ignoring this?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: shape.setTexture() problems
« Reply #7 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
Laurent Gomila - SFML developer

kapesu8

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: shape.setTexture() problems
« Reply #8 on: May 05, 2012, 11:28:19 pm »
I'm probably too lazy but could you just tell me why that doesn't work?

Vovosunt

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: shape.setTexture() problems
« Reply #9 on: May 06, 2012, 12:07:16 am »
This isn't even an SFML problem.... *facepalm*
Ever heard of pointers and references?  ::)

kapesu8

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: shape.setTexture() problems
« Reply #10 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: shape.setTexture() problems
« Reply #11 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.
Laurent Gomila - SFML developer

kapesu8

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: shape.setTexture() problems
« Reply #12 on: May 06, 2012, 10:51:21 am »
Am I supposed to do it like
sf::Texture *texture
?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: shape.setTexture() problems
« Reply #13 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

kapesu8

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: shape.setTexture() problems
« Reply #14 on: May 06, 2012, 12:11:51 pm »
Oh.. It was just..
  rect.setTexture(&texture);

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