Array of classes with scenenodes in them

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.

Array of classes with scenenodes in them

Postby eejin » Tue Jul 24, 2012 12:22 pm

Hi, I've been trying to implement a basic creature in my game and I decided I should use classes for them because I want to alter their location and such seperatly.
Now I though of creating an array that has pointers to all the objects. This works fine but now I want to be able to say I want to have a new object of the class and set the model.

cpp Code: Select all
class Zombie {
    char mesh;
    public:
    void set_mesh (char);
};
 
void Zombie::set_mesh (char mesh) {
  mesh = mesh;
}


Now how would I create a new scenenode everytime a new object of the class Zombie is created?
I got an array that has pointers to meshes I load so I don't have to load a mesh everytime I create a new Zombie.
eejin
 
Posts: 93
Joined: Sun Jul 24, 2011 11:50 am

Re: Array of classes with scenenodes in them

Postby CuteAlien » Tue Jul 24, 2012 1:26 pm

Irrlicht caches meshes - which means ISceneManager::getMesh doesn't load again if it already has such a mesh. Now for creating different nodes for those meshes use ISceneManager::addMeshSceneNode or ISceneManager::addAnimatedMeshSceneNode. Then you can put the resulting ISceneNodePointer (or one of it's derived classes) into your Zombie class and control the node by that.
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5364
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Array of classes with scenenodes in them

Postby eejin » Wed Jul 25, 2012 2:29 pm

But I can't call addAnimatedMeshSceneNode in the class because the scenemanager is not yet initialized. How would I create a node which is connected to the class object?
eejin
 
Posts: 93
Joined: Sun Jul 24, 2011 11:50 am

Re: Array of classes with scenenodes in them

Postby CuteAlien » Thu Jul 26, 2012 11:56 pm

Pass the scenemanager as parameter. Although it often is better to have a second class doing the creation - so you would have for example a class that has a function like createZombie. A good name for such a class might be Zombiefactory (if all it can do is creating zombies).
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5364
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Array of classes with scenenodes in them

Postby randomMesh » Fri Jul 27, 2012 12:06 am

cpp Code: Select all
 
zombieFactory->createZombie(EEF_EVIL);
 

This is why i love oop. :-)
"In fact, nearly every sequence of punctuation is used for something in Perl. So, if you get writer’s block, just let the cat walk across the keyboard, and debug the result."

Katastrophe - A free, open source flocking boids simulation
User avatar
randomMesh
 
Posts: 1138
Joined: Fri Dec 29, 2006 12:04 am

Re: Array of classes with scenenodes in them

Postby hendu » Fri Jul 27, 2012 10:03 am

That reminded me of the old Java joke.. Use java and all you have is a ProblemFactory.
hendu
 
Posts: 1560
Joined: Sat Dec 18, 2010 12:53 pm


Return to Beginners Help

Who is online

Users browsing this forum: No registered users and 1 guest