SFML community forums

Help => Graphics => Topic started by: loogie on April 04, 2012, 07:33:27 pm

Title: Is there a Sprite "Node" equivilant
Post by: loogie 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?
Title: Re: Is there a Sprite "Node" equivilant
Post by: eXpl0it3r 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 (http://en.wikipedia.org/wiki/Scene_graph), aren't you?
Title: Re: Is there a Sprite "Node" equivilant
Post by: loogie 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.
Title: Re: Is there a Sprite "Node" equivilant
Post by: Laurent 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);
    }
}