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

Author Topic: [SOLVED] Some questions about Scenegraph  (Read 1598 times)

0 Members and 2 Guests are viewing this topic.

xmax3

  • Newbie
  • *
  • Posts: 6
    • View Profile
[SOLVED] Some questions about Scenegraph
« on: March 28, 2014, 03:26:00 pm »
Hi ! I'm actually coding a little game and I have some problem with scenegraph implementation.
Here's my base Node class:

class Node: public sf::Drawable, public sf::Transformable
{

public:

    Node(const sf::Vector2f & origin, const sf::Vector2f & pos,
               const std::string & id, bool drawnAbove = true);

    virtual void Step(sf::Time frametime);

    //Add a new child to the node.
    bool BindNode(std::unique_ptr<Node> & node);
    //Remove a child and get it.
    std::unique_ptr<Node> UnbindNode(const std::string & id);

    //Get a child with it ID.
    Node * GetChild(const std::string & id);
    unsigned int GetChildCount() const;

    const std::string & GetId() const;

    void SetDrawnAboveParent(bool drawnAbove);
    bool IsDrawnAboveParent() const;

    virtual void OnDraw(sf::RenderTarget & target, const sf::Transform & trans) const;

protected:

    virtual void draw(sf::RenderTarget &target, sf::RenderStates States) const;

    //Childs.
    std::map<std::string, std::unique_ptr<Node> > m_childs;

    std::string m_id;

    bool m_drawnAboveParent;

};

I also implemented a spriteNode and an animationNode which have Node as base class. My question is:

If I use those classes to create an animated character (for example): Every part of the character would be a spriteNode which has as parent an animationNode (walk animation, attack animation, etc...).  How can I access the animation node and modify them effectively to the animation I want ?

Thanks for your answer !  ;)
« Last Edit: March 30, 2014, 10:36:36 pm by xmax3 »
Hello ! Just to advise you that my first language is french, so my english may not be perfect. I want to improve it, so I prefer to go in the english forums. Thank you!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Some questions about Scenegraph
« Reply #1 on: March 28, 2014, 04:20:54 pm »
I doubt that it's wise to model animation as a node in the scene graph. After all, the animation itself is not part of the scene, only the animated objects are.

I would rather use a non-intrusive approach. You could have a look at my library Thor with its Animation module (API doc, tutorial). For example, each sprite node could then store an additional thor::Animator which is responsible of animating the sprite.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

xmax3

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Some questions about Scenegraph
« Reply #2 on: March 30, 2014, 09:48:49 pm »
Hello ! Thanks for your answer :P
I was very busy this week-end, so I didn't have the time to look back for the answer.

I had a doubt too on that way of doing it, but I was not sure about storing the instance that's responsible of the animation in the node.

I suppose that the best way to change the animation is to set the playing animation (animator.playAnimation(...) ) in the parent and apply it for every childs ?
Hello ! Just to advise you that my first language is french, so my english may not be perfect. I want to improve it, so I prefer to go in the english forums. Thank you!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Some questions about Scenegraph
« Reply #3 on: March 30, 2014, 09:58:07 pm »
I suppose that the best way to change the animation is to set the playing animation (animator.playAnimation(...) ) in the parent and apply it for every childs ?
It depends on what the children represent. You talked about different character parts? If they can be animated independently from each other (every part defines has its own implementation of a specific animation), then yes, that could be the way to go.

Otherwise you have to explain more about your problem.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

xmax3

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Some questions about Scenegraph
« Reply #4 on: March 30, 2014, 10:35:42 pm »
Yeah, in this example it represent different character parts.

I think that I have all that I needed to continue. Thanks again, I'll mark my topic as solved ;)
Hello ! Just to advise you that my first language is french, so my english may not be perfect. I want to improve it, so I prefer to go in the english forums. Thank you!