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

Author Topic: [Solved] Text Coords and Shape Coords  (Read 12195 times)

0 Members and 1 Guest are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[Solved] Text Coords and Shape Coords
« Reply #30 on: January 01, 2011, 11:30:13 pm »
I don't know why people want to keep their code structure, namespaces etc. in minimal codes ;)

Here is what I ended up with after 30 sec:
Code: [Select]
#include <iostream>
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "test");

    sf::Shape canvas = sf::Shape::Rectangle(100, 100, 400, 400, sf::Color::White, 5, sf::Color::White);
    canvas.EnableFill(false);
    canvas.EnableOutline(true);
    canvas.SetPosition(100, 100);

    sf::String text;
    text.SetPosition(100, 100);
    text.SetText("Text String");

    while (window.IsOpened())
    {
        window.Clear();
        window.Draw(canvas);
        window.Draw(text);
        window.Display();
    }

    return 0;
}

But I'm just quibbling, your code was good enough, thank you ;)

Now the error: you put your rectangle's geometry at 100,100, and then you move this geometry to 100,100: the geometry ends up at 200,200. The position of the shape's points is not the global position that you set with SetPosition. They are combined.
Laurent Gomila - SFML developer

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
[Solved] Text Coords and Shape Coords
« Reply #31 on: January 01, 2011, 11:38:12 pm »
Wow! That's it? I thought the .Move() member was the one that combined. So What's the difference between .Move() and .SetPosition()?
Also, how would I go about just setting a new position for it without combining it.
-Wander

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[Solved] Text Coords and Shape Coords
« Reply #32 on: January 02, 2011, 12:02:24 am »
No you misunderstand me. Move and SetPosition modify the same variable, the first one is relative to the current position and the second one absolute.

But the coordinates that you pass to sf::Shape::Rectangle define the local position of points. This is a totally different thing. If you want to play with the position of your rectangle, create it at 0,0 and only use SetPosition.
Laurent Gomila - SFML developer

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
[Solved] Text Coords and Shape Coords
« Reply #33 on: January 02, 2011, 12:07:18 am »
OH!! I get it now! So, if I set the Rectangle originally at 100, 100 then that would act like a 0, 0?
-Wander

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[Solved] Text Coords and Shape Coords
« Reply #34 on: January 02, 2011, 12:18:34 pm »
Quote
OH!! I get it now! So, if I set the Rectangle originally at 100, 100 then that would act like a 0, 0?

Yes, when the rectangle is at position 0,0, its top-left corner is already at 100,100.
Laurent Gomila - SFML developer

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
[Solved] Text Coords and Shape Coords
« Reply #35 on: January 02, 2011, 08:18:30 pm »
Okay. Thanks. :)
-Wander

 

anything