5 replies to this topic
#1 Members - Reputation: 392
Posted 16 December 2012 - 11:01 AM
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.
Ad:
#3 Marketplace Seller - Reputation: 8925
Posted 16 December 2012 - 11:25 AM
Use a vector:
When you are ready to create a new one, call:
When drawing or updating enemies, you iterate over the entire vector.
std::vector<MyEnemy> enemies;
When you are ready to create a new one, call:
enemies.push_back(MyEnemy(model, animation, position, rotation, scale, etc...);
When drawing or updating enemies, you iterate over the entire vector.
Edited by Servant of the Lord, 16 December 2012 - 11:25 AM.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal
#5 Members - Reputation: 2043
Posted 16 December 2012 - 12:29 PM
The factory pattern might be of interest to you: http://en.wikipedia.org/wiki/Factory_method_pattern







