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

Author Topic: Why can't I multiply a vector2 when using setPosition but I can when using move?  (Read 1898 times)

0 Members and 1 Guest are viewing this topic.

Ignatius_Z

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
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 :)

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
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

Ignatius_Z

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
I swear I already tried that but I tried it again and it worked. Thanks heaps  ;D

 

anything