I am now working on a 2nd project (I like to have more then one project going at a time so I can go back and forth between projects Keeps me from getting bored with a project) My 2nd project is a Life simulation game called My Life. Its a game kind of like the sims where you can create a family and then build a house for them and buy them stuff.
I was wondering what the best way would be to program it so that you can add items during game play? I know you have to make the stuff in a 3d program first but how would I program it so that for example when I click on buy on the GUI a menu pops up with a bunch of items then you select which item you want and click on the screen where ever you want it to go and it appears on the screen?
Adding object during game play
That sounds like about five different questions in one. It sounds like what you want to know is how to make something your character has bought appear on the screen. Is this what you really want to know? If so then here is a quick (and very simplified ) series of steps:
1) make the mesh in a 3D program (like Blender, 3dsMax or Maya, for instance).
2) In the code, make sure to add the directory folder that contains the mesh file:
3) Load the mesh and add it to the scene:
Don't forget to set the texture, lighting and such for 'newNode'.
1) make the mesh in a 3D program (like Blender, 3dsMax or Maya, for instance).
2) In the code, make sure to add the directory folder that contains the mesh file:
Code: Select all
device->getFileSystem()->addFolderFileArchive ( "C:\\MyGame\\res\\images\\GPIcons" );Code: Select all
irr::scene::IAnimatedMesh* myAnimatedMesh = smgr->getMesh("houseplant.obj");
irr::core::ISceneNode *newNode = smgr->addAnimatedMeshSceneNode(myAnimatedMesh);You would have to make a list of some sort that can hold new objects.
Irrlicht has an some useful templates for arrays and lists and stuff. When the player wants to add something, make a new instance of it and push it onto the array or list.
For example, here is the documentation for array: http://irrlicht.sourceforge.net/docu/cl ... array.html
You would make an array of your object like this:
Then whenever the player makes an object, you could put it into the array like this:
This way, you can make as many objects as you want, and store them.
However, it's probably much better to use a map instead of an array. That way you can name your name your objects with a key and so you can find them much easier when you need them again.
Irrlicht has an some useful templates for arrays and lists and stuff. When the player wants to add something, make a new instance of it and push it onto the array or list.
For example, here is the documentation for array: http://irrlicht.sourceforge.net/docu/cl ... array.html
You would make an array of your object like this:
Code: Select all
irr::core::array<myItemClass*> myArray();Code: Select all
myItemClass* theNewItemObject();
myArray.push_back(theNewItemObject);However, it's probably much better to use a map instead of an array. That way you can name your name your objects with a key and so you can find them much easier when you need them again.
-
rogerborg
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Re: Adding object during game play
Have you tried using divide and conquer reasoning?
Step 1: Model the item.empirepro wrote:I was wondering what the best way would be to program it so that you can add items during game play? I know you have to make the stuff in a 3d program first
Step 2: write a GUI, following the examples in the tutorials.empirepro wrote:but how would I program it so that for example when I click on buy on the GUI
Step 3: Add items to the GUI (listbox?) using an idiom that's entirely dependent on your application.empirepro wrote:a menu pops up with a bunch of items
Step 4: Standard GUI functionality, mapping to your item idiom.empirepro wrote:then you select which item you want
Step 5: Find the position of the mouse cursor in your world, which is entirely dependent on your application. There are a plethora of examples of how to do mouse picking/intersection with a world. You'll need to be more specific if you want help with this.empirepro wrote:and click on the screen where ever you want it to go
Step 6: Create a new game object for the item (using an idiom dependent on your application) and an Irrlicht representation of it using (most likely) addAnimatedMeshSceneNode(), unless of course you really are using 2D, in which case you might want addBillboardSceneNode(), or in fact just have your game item draw it itself in the render loop using IVideoDriver::draw2DImage(). It's really, uh, dependent on your application.empirepro wrote:and it appears on the screen?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Would it be possible to have the GUI load all thumbnails from a predefined folder? Each thumbnail would be associated with a object. So for example you have a folder in the game directory call Kitchen. In the Kitchen folder you have .3DS files called stove.3DS and Microwave.3DS theres also a folder called thumbnails under the kitchen folder that has the thumbnails for stove.3ds and mircowave.3ds Is it possible to instead of saying look for stove.3ds and microwave.3ds just predefine the folder Kitchen and have it load the thumbnails for all the objects found in the kitchen folder so if the player puts in lets say sink.3ds and in the thumbnail directory put sink.jpg it will not only load stove.3ds and microwave.3ds but sink.3ds as well? I hope this makes since.
That's very possible, but it will require a bit of work on your part.
Basically all you have to do is get a list of the files in the Kitchen folder (irrlicht's filereading functions may provide this operation) and then load each accordinly.
so you might have this:
So you'd get your list of contents of the Kitchen folder, the files would be stove.3ds and mwave.3ds so you'd load them and knowing their names you could then look in the thumbnails folder for stove.jpg and mwave.jpg.
Basically all you have to do is get a list of the files in the Kitchen folder (irrlicht's filereading functions may provide this operation) and then load each accordinly.
so you might have this:
Code: Select all
Kitchen
Thumbnails
- stove.jpg
- mwave.jpg
- stove.3ds
- mwave.3ds
