Advertisement

HELP SFML

Started by September 13, 2015 05:20 PM
6 comments, last by BitMaster 9 years, 3 months ago

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 ?

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?
Advertisement
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.

Thanks ! i am studying sfml , i am going to make pong after tutorials

Why are you extracting the texture when you could use sf::Sprite::getLocalBounds?

Why are you extracting the texture when you could use sf::Sprite::getLocalBounds?

i am learning sfml and thats what tutorial teaches , if there is a easier way i would like to learn

Advertisement

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
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.

This topic is closed to new replies.

Advertisement