Sign in to follow this  

HELP SFML

This topic is 825 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
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

This topic is 825 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this