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

Author Topic: SFML best objekt for drawing  (Read 1967 times)

0 Members and 1 Guest are viewing this topic.

Michalus

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
SFML best objekt for drawing
« on: July 19, 2013, 02:12:34 pm »
I want to make draw method, for a GameObject, but I dont want to give a pointer to the RenderWindow, because I can in the RenderWindow set for example the size, too.
have SFML a Class with that, I can draw something, or must I made a class myself?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: SFML best objekt for drawing
« Reply #1 on: July 19, 2013, 03:59:07 pm »
I don't really get what you want to do.
SFML can draw everything that derives from sf::Drawable, which includes sf::Sprite, sf::RectangleShape and a few others. Next to that it can draw sf::VertexArray or just an array of sf::Vertex.

So if you have already an object, but don't want to pass the window itself, then you could derive that object from sf::Drawable and implement the draw function. So you could do window.draw(myObject).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

solver

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: SFML best objekt for drawing
« Reply #2 on: July 19, 2013, 10:03:43 pm »
Just make your GameObject deriving from sf::Drawable, and implement draw method. Somethin like this (dont afraid, it is java):
@Override
public void draw(RenderTarget target, RenderStates states) {
    target.draw(sprite, states);
    drawBoundingBox(target, states);
}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
AW: SFML best objekt for drawing
« Reply #3 on: July 19, 2013, 10:05:31 pm »
Not sure how Java code will help a C++ programmer. :D
Rather read the tutorial. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

solver

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: SFML best objekt for drawing
« Reply #4 on: July 19, 2013, 11:11:54 pm »
In this case, no matters what language to use. I just want to show how can be draw method implemented. You know that better than me, so you can show it in c++.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: SFML best objekt for drawing
« Reply #5 on: July 19, 2013, 11:46:46 pm »
I don't have to, since everything is neatly explained in the official tutorials, which everyone should read before asking how to properly use SFML. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/