Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Dynamically create class object?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 proanim   Members   -  Reputation: 392

Like
0Likes
Like

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.

Sponsor:

#2 Telastyn   Members   -  Reputation: 3332

Like
0Likes
Like

Posted 16 December 2012 - 11:10 AM

By having a class with model, animation, position, rotation, scale, etc. Read in input, create object, tahdah.

#3 Servant of the Lord   Marketplace Seller   -  Reputation: 8955

Like
0Likes
Like

Posted 16 December 2012 - 11:25 AM

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.

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


#4 lride   Members   -  Reputation: 615

Like
0Likes
Like

Posted 16 December 2012 - 11:58 AM

also look at entity component system
An invisible text.

#5 Radikalizm   Members   -  Reputation: 2047

Like
0Likes
Like

Posted 16 December 2012 - 12:29 PM

The factory pattern might be of interest to you: http://en.wikipedia.org/wiki/Factory_method_pattern

#6 Telastyn   Members   -  Reputation: 3332

Like
1Likes
Like

Posted 16 December 2012 - 03:13 PM

also look at entity component system


There's no reason to resort to this.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS