Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


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: 441

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   Crossbones+   -  Reputation: 3726

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   Crossbones+   -  Reputation: 20245

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.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
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

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#4 lride   Members   -  Reputation: 633

Like
0Likes
Like

Posted 16 December 2012 - 11:58 AM

also look at entity component system
An invisible text.

#5 Radikalizm   Crossbones+   -  Reputation: 2912

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

I gets all your texture budgets!


#6 Telastyn   Crossbones+   -  Reputation: 3726

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