SFML community forums

Help => Graphics => Topic started by: Ignatius_Z on February 02, 2021, 12:01:23 am

Title: Why can't I multiply a vector2 when using setPosition but I can when using move?
Post by: Ignatius_Z on February 02, 2021, 12:01:23 am
Sorry for possibly very noob question but I've googled thoroughly and I don't where else to ask.

For some reason when using Sprite.move I can freely multiply the Vector2f I put in it but when I use Sprite.setPosition it gives an error.

for example:

int main()
{
     Sprite mySprite;

     Vector2f direction(1, 1);
     
     while (window.isOpen())
     {
            mySprite.move(direction * 0.5);
     }
}

This works fine but when I try:

int main()
{
     Sprite mySprite;

     Vector2f direction(1, 1);
     
     while (window.isOpen())
     {
            mySprite.setPosition(direction * 100);
     }
}

I get the error:

"no match for 'operator*' (operand types are 'double' and 'sf::Vector2f' {aka 'sf::Vector2<float>'})|"

Please let me know what the issue is and thanks in advance and sorry for any formatting errors :)
Title: Re: Why can't I multiply a vector2 when using setPosition but I can when using move?
Post by: G. on February 02, 2021, 12:10:43 am
It's unrelated to move or setPosition.
sf::Vector2f is a vector of floats, and you can multiply it by floats.
* 100 is multiplying by an int, that is automatically converted to a float.
* 0.5 is multiplying by a double, that is not automatically converted to a float.

0.5 is a double
0.5f is a float
Title: Re: Why can't I multiply a vector2 when using setPosition but I can when using move?
Post by: Ignatius_Z on February 02, 2021, 12:24:35 am
I swear I already tried that but I tried it again and it worked. Thanks heaps  ;D