Dynamically create class object?

Started by
4 comments, last by Telastyn 11 years, 4 months ago
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.
Advertisement
By having a class with model, animation, position, rotation, scale, etc. Read in input, create object, tahdah.
Use a 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.
also look at entity component system
An invisible text.
The factory pattern might be of interest to you: http://en.wikipedia.org/wiki/Factory_method_pattern

I gets all your texture budgets!


also look at entity component system


There's no reason to resort to this.

This topic is closed to new replies.

Advertisement