Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / How to make mulitple objects like trees?

Author
Message
urgent help!
15
Years of Service
User Offline
Joined: 28th Sep 2010
Location:
Posted: 3rd Nov 2010 20:39
Hello again. I was wondering how i would make mulitple objects like trees and put them into my game. Would I use a for next loop or what? thank you.
bergice
19
Years of Service
User Offline
Joined: 5th Jun 2007
Location: Oslo,Norway
Posted: 3rd Nov 2010 23:36 Edited at: 3rd Nov 2010 23:39
Did a small example, this code will not run, you need to have the tree.x model and make a loop so you can have a look at the trees.




It loads a tree model and copies it 512 times, and then places those trees randomly around.

51fa1db0ec7c4af52d93a6f5d0e86bc5


Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 4th Nov 2010 02:52 Edited at: 4th Nov 2010 02:58
http://forum.thegamecreators.com/?m=forum_view&t=138206&b=1

This is a demo I posted a while back that includes this very thing.
It's not just important to create a bunch of objects, but also to keep track of them.

Also in the Demo:
It's generally good (when making a level) to refrain from hard coding the path names of objects, sounds, etc. Let a "Level File" completely dictate what objects get loaded, and where they go.

The Demo was posted so you could tear it apart and see how it works.

Rain Man
18
Years of Service
User Offline
Joined: 19th Nov 2007
Location:
Posted: 4th Nov 2010 07:38
Bergice,

Quote: "//dont need our base tree anymore
delete object treeMDL"


You can't delete the original object which has been instanced without losing all of the instances. Whatever happens to the original happens to all of the objects instanced from it.



As far as I know, the only variations in instanced objects can be in position, rotation and scale.

Quote: "//Not sure if instance object or clone object is best."


In this case, instancing is best. Except for position, rotation and scale, the trees will all be the same (although you could instance a couple of different models for variety). Instancing requires substantially fewer system resources, as there’s only one set of object data in memory regardless of the number of instances. All of the instanced objects share the object data of the original. This has the additional benefit that you only need to animate the original object in order to animate all of them (in this case, having the branches move to simulate the wind, perhaps).

Cloning is required if you need some other variation between the objects, as each clone is a new and separate object unrelated to the original. Each cloned object has its own complete set of object data thus requiring greater system resources. This being the case, you can delete the original object and not lose the objects cloned from it. And you can make changes to individual clones or apply individual animations to them. Therefore, cloning gives greater flexibility than instancing.

Ten minutes to Wapner.
urgent help!
15
Years of Service
User Offline
Joined: 28th Sep 2010
Location:
Posted: 4th Nov 2010 19:09
Thank you all for helping me =) I decided to go with rain man's code and it works out great

Login to post a reply

Server time is: 2026-07-26 05:03:35
Your offset time is: 2026-07-26 05:03:35