• Advertisement
Sign in to follow this  

Dynamically create class object?

This topic is 1859 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am looking for the way to create new class object at the run time. What I had in mind was if I have a class 'enemy' that can define enemy model, animation, position, rotation, scale, etc. How can I create another object that will define new enemy? I want to do this without restricting my program with predefinded class id and such.

Share this post


Link to post
Share on other sites
Advertisement
By having a class with model, animation, position, rotation, scale, etc. Read in input, create object, tahdah.

Share this post


Link to post
Share on other sites
Use a vector:
[code]std::vector<MyEnemy> enemies;[/code]

When you are ready to create a new one, call:
[code]enemies.push_back(MyEnemy(model, animation, position, rotation, scale, etc...);[/code]

When drawing or updating enemies, you iterate over the entire vector. Edited by Servant of the Lord

Share this post


Link to post
Share on other sites
[quote name='lride' timestamp='1355680684' post='5011314']
also look at entity component system
[/quote]

There's no reason to resort to this.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement