Skip to main content
GameDev.net gamedev.net
🔒 Locked

Dynamically create class object?

Started by proanim Dec 16, 2012 at 5:01 PM 4 replies 1.3k views
Original Post
proanim
proanim
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.
Servant of the Lord
Servant of the Lord
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.
lride
lride
also look at entity component system
An invisible text.
Radikalizm
Radikalizm
The factory pattern might be of interest to you: http://en.wikipedia.org/wiki/Factory_method_pattern
I gets all your texture budgets!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.