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

Author Topic: Create shape and set it's position in one line?  (Read 1951 times)

0 Members and 1 Guest are viewing this topic.

Gauzr

  • Newbie
  • *
  • Posts: 20
    • View Profile
Create shape and set it's position in one line?
« on: June 17, 2015, 11:14:49 pm »
I would like to know if it's possible, as it would be a lot more efficient in my game I am making.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Create shape and set it's position in one line?
« Reply #1 on: June 17, 2015, 11:18:24 pm »
sf::RectangleShape rectangle(sf::Vector2f(120, 50)); rectangle.setPosition(20, 35);

 :P
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Gauzr

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Create shape and set it's position in one line?
« Reply #2 on: June 17, 2015, 11:18:40 pm »
Ah, thanks  ;)

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Create shape and set it's position in one line?
« Reply #3 on: June 17, 2015, 11:22:09 pm »
To be perfectly honest, that's cheating, it's not really one line, and not more efficient. :)

But besides that, don't worry about performance there. It probably won't cause any significant slowdown.

If it does, think about why you have to recreate the shape rather than reusing it.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Create shape and set it's position in one line?
« Reply #4 on: June 17, 2015, 11:31:58 pm »
It was more of a tongue-in-cheek answer than an efficient solution  :)

If efficiency here is speed, it's not the separate position setting that's slowing you down.  ;)
If efficiency here is code layout, there's no real need for this efficiency. It's actually worse as it can lead to mis-reading (forgetting the secondary statement, for example).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything