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

Author Topic: Is there a Sprite "Node" equivilant  (Read 2584 times)

0 Members and 1 Guest are viewing this topic.

loogie

  • Newbie
  • *
  • Posts: 3
    • View Profile
Is there a Sprite "Node" equivilant
« on: April 04, 2012, 07:33:27 pm »
In a lot of engines, there something called a "Node" (or similar) class... which is basically an object that can draw sprites, but can also is drawable.. basically it should be a sprite, which contains a number of sprites.  Is there any equivilant to that in SFML? if not would it be possible to make something like it?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Is there a Sprite "Node" equivilant
« Reply #1 on: April 04, 2012, 07:54:57 pm »
I'm not sure if I got you right, do you want to draw multiple sprites with just one draw call?
For this most of the SFML 2 graphics API got changed, you can now use sf::VertexArray to create your own primitives with textures. Also if you want jsut to 'collect' some of the sprites in one texture you can also render to sf::RenderTexture and then just render the texture of it. But keep in mind if you draw to the sf::RenderTexture every frame, you'd better of rendering directly to the window for performance reasons.

For the "Node" thing, I guess you're refering to a scene graph, aren't you?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

loogie

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Is there a Sprite "Node" equivilant
« Reply #2 on: April 04, 2012, 08:13:10 pm »
I think the first thing...

I would like to be able to draw multiple sprites to a "container sprite" and then also be able to transform that, which would also transform it's children... how many engines seem to work, flixel, starling, jMonkey all seem to adopt this concept of a parent group drawing children idea

an example would be to draw a character and a sword... two sprites.

draw the character to the "node" with the usual information.
draw the sword to the "node", move it's position to 100,100 at a rotation of 45 degrees.

draw the "node" to the screen, rotate it by 180 degrees.

The result would be like drawing character and sword to node... then rotating the whole thing 180 degrees together.
« Last Edit: April 04, 2012, 08:23:31 pm by loogie »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Is there a Sprite "Node" equivilant
« Reply #3 on: April 04, 2012, 10:05:47 pm »
SFML is not an engine, there's no scene graph in it. But this doesn't mean that you can't create entity hierarchies, and combine transformations. This is very easy to do with SFML.

An example:
class MyContainer : public sf::Drawable, public sf::Transformable
{
public:

    /* functions to manage child entities */

private:

    virtual void draw(sf::RenderTarget& target, sf::RenderStates states)
    {
         states.transform *= getTransform();

         for (/* all child entities */)
             target.draw(entity, states);
    }
}
Laurent Gomila - SFML developer

 

anything