Jump to content
  • Advertisement
Sign in to follow this  
MrMato

HELP SFML

This topic is 1041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi!

 

 

sprite.setOrigin(sf::Vector2f(sprite.getTexture()->getSize().x * 0.05, sprite.getTexture()->getSize().y * 0.05));

 

i dont understand this part can anyone explain this operator (->) and sprite.getTexture()->getSize().x  ?

Share this post


Link to post
Share on other sites
Advertisement
The "->" is the pointer de-reference operator into structs and classes, which is explained in the chapter about pointers.
 
class X {
public:
    X() { x = 4; }

    int x;
};

X *p = new X();
p->x = 5; // Assign 5 to the 'x' variable in the *p instance.
"p->x" is equivalent to "(*p).x".


sprite.getTexture()->getSize().x
You seem to have a "sprite" variable, where you apply the "getTexture()" method to. Its result is a pointer to a object where you apply "getSize()" to. Its result is an object with an "x" data member, which you retrieve.



Perhaps do some simpler C++ games first, like hangman? Edited by Alberth

Share this post


Link to post
Share on other sites
The arrow operator is syntactic sugar for a dereference and member access:

ptr->a is equivalent to (*ptr).a


Now, "sprite.getTexture()->getSize().x" is exactly how it reads: It retrieves the width of the sprite's texture's size.

Share this post


Link to post
Share on other sites

can  anyone explain ?

 

 

bool intersects(const sf::RectangleShape & rect1, const sf::RectangleShape & rect2){

 
FloatRect r1 = rect1.getGlobalBounds();
FloatRect r2 = rect2.getGlobalBounds();
return r1.intersects(r2)
 
and i cant use Vector2  it says class template missing
Edited by MrMato

Share this post


Link to post
Share on other sites
According to the documentation sf::Vector2 is a template. Considering you used Vector2f above I would assume there is already a handy typedef for a float Vector2 available.

That said, none of your problems so far had anything to do with SFML but the very basics of C++. I would strongly suggest you forget about SFML for now and work on a significantly more solid foundation in your language of choice first. Edited by BitMaster

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!