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

Author Topic: SFML game development book, what is SpriteNode class for ?  (Read 2884 times)

0 Members and 1 Guest are viewing this topic.

bcvz

  • Newbie
  • *
  • Posts: 17
    • View Profile
SFML game development book, what is SpriteNode class for ?
« on: February 16, 2014, 09:09:37 pm »
Hello

https://github.com/SFML/SFML-Game-Development-Book/blob/master/10_Network/Include/Book/SpriteNode.hpp

I don't see the utility of this class
where is it used ?

you can't use it as is because all of the virtual methods (from SceneNode) aren't defined, so you have to make a class which derives from it I guess ?

but if I make a class which derives from SpriteNode i'll not be able to use SpriteNode's constructor, am I ?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML game development book, what is SpriteNode class for ?
« Reply #1 on: February 16, 2014, 09:55:18 pm »
I don't see the utility of this class
where is it used ?
It's used for the world's background. By the way, you can search for its occurrences in the project (either directly on GitHub or after you've cloned the repository).

you can't use it as is because all of the virtual methods (from SceneNode) aren't defined
They are defined, mostly in SceneNode itself. Otherwise the code wouldn't link...

but if I make a class which derives from SpriteNode i'll not be able to use SpriteNode's constructor, am I ?
Yes, you are, but I don't see a reason to derive from it. It seems as if you lack some knowledge about classes and inheritance in C++, maybe a C++ book would be a good idea ;)
« Last Edit: February 16, 2014, 09:57:15 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

bcvz

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: SFML game development book, what is SpriteNode class for ?
« Reply #2 on: February 16, 2014, 10:19:57 pm »
Quote
They are defined, mostly in SceneNode itself. Otherwise the code wouldn't link...

yeah it seems that it works with no pure virtuals but I use pure virtuals with "=0;" (in Scenenode) so it wasn't working for me ( I mean I can't use it as is )

I have a MouseArea class which is derived from SpriteNode.

I initialize it like this (in a class constructor) : mouseArea = MouseArea::Ptr (new MouseArea(mouseAreaTexture));

MouseArea has no constructor but SpriteNode has.
I have this error message:
no instance of constructor "MouseArea::MouseArea" matches the argument list
            argument types are: (sf::Texture)

how do I use SpriteNode's constructor if it's possible to use it with a derived class as you said?

sorry i'am a newbie

edit:
And one question about this SceneNode system. So they are Scenenodes and they all have childrens we can only update and draw them ..
But what if I want to sent an information to a specific child ? For example I want to send mousePosition every frame to MouseArea but it's a child of my map.
« Last Edit: February 16, 2014, 10:31:55 pm by bcvz »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML game development book, what is SpriteNode class for ?
« Reply #3 on: February 16, 2014, 10:35:48 pm »
yeah it seems that it works with no pure virtuals but I use pure virtuals with "=0;" (in Scenenode) so it wasn't working for me ( I mean I can't use it as is )
Yes, that's the whole point of pure virtual functions: one has to define them in derived classes...

I have a MouseArea class which is derived from SpriteNode.
Is there a reason why you use inheritance? Why not composition, or even use SpriteNode directly? The Liskov Substitution Principle might also be worth reading.

how do I use SpriteNode's constructor if it's possible to use it with a derived class as you said?

sorry i'am a newbie
You can do it in the initializer list of the derived class' constructor. It doesn't make much sense if explain all the details here, they will only raise further questions. You should really get a good book and learn C++ before delving into SFML or game development; the book clearly states that a solid understanding of the programming language is required (this is even more true in case you want to learn only from the code without the book). Sorry if this sounds a bit harsh, but you can't simply omit C++ theory when you want to develop and understand C++ games :)

But what if I want to sent an information to a specific child ? For example I want to send mousePosition every frame to MouseArea but it's a child of my map.
The command system is used for exactly this purpose: delivering messages with specific information among the scene nodes.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: