node deletion

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.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Yeah, it should be linear_reverse_search. As for where 'node' came from, it is the node that you are about to remove from the scene. It could come from anywhere.

As I said before, unless you have a really good reason to maintain an external array of scene nodes, it should be avoided. Why do you think that you need the external array?

Travis
kennypu666
Posts: 26
Joined: Thu Apr 26, 2007 6:57 am

Post by kennypu666 »

i was going to use an array for example the enemys in a fps, so i dont have to make each one seperatly. at the moment i dont really need an array because im stlil trying to figure out how to check if the bullet collided, how to delete them,etc. but yea thats about it.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Ah, sorry I lost track of which post was which. Yes, it makes sense to use an array for bullets and for enemies. If you had an array of bullets that would go away after some preset time interval, you wouldn't need to search for which bullet to remove. You would probably have a function to walk over the bullets and see if any of them passed through a bad guy since the last time you checked. If your bullets could 'expire', you'd check to see if each had expired, and if it had you'd remove it from the scene and from the array.

Travis
kennypu666
Posts: 26
Joined: Thu Apr 26, 2007 6:57 am

Post by kennypu666 »

yea, I have a thing for the bullets alread. its not an array though. I still have a question about making the array because I dont know how to do it. I tried a way and no errors but the program crashed so i guess i did it wrong. I still dont understand how the "node" came from. this is what i did.

Code: Select all

    core::array<scene::ISceneNode*> SceneNodes; //da array for enemy(boxes)
    //create a node and add it to the array
    SceneNodes.push_back(smgr->addCubeSceneNode(100.0f));
    scene::ISceneNode* bnode = SceneNodes[0];
and this is the part where i use node->remove();

Code: Select all

            s32 found = SceneNodes.linear_reverse_search(bnode);
                    if (found != -1)
                       SceneNodes.erase(found);
                    bnode->remove();
srry for being so stupid.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Have you tried "addToDeletionQueue" Instead of remove? Its supposed to wait till the node is free before trying to remove it.
kennypu666
Posts: 26
Joined: Thu Apr 26, 2007 6:57 am

Post by kennypu666 »

thanks for the idea, but it still crashed. I just think that i specified bnode wrong. anybody know how to set a node the right way? sorry lol.
Post Reply