Jump to content
  • Advertisement
Sign in to follow this  

Game Object Factory Questions

This topic is 2709 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm making a Top-Down Shooter and I think the Factory pattern would be useful. I'm planning to use the Flyweight pattern for my game entities, which seems a Factory would make easier to implement, and keeping track of entities seems like it would be easier with a Factory system.

My current plan is to have something like this:

class EntityFactory
- List of Flyweights
- Code to handle Flyweights
- Separate function to create each class which inherits from Entity, e.g. createCreature(), createWeapon(), createItem() etc.

1. Would separate Factory objects for each type be better? Or could that layout be improved?

2. Logically, it doesn't make sense for a Creature to be able to be assigned a Flyweight designed for a Weapon. So I've decided I should probably have WeaponFlyweight, CreatureFlyweight etc. and have them (possibly) inherit from Flyweight.
If they inherit, then I suppose I could have a single database of Flyweight objects and then cast them to the correct type when an Entity is being created. Does that sound like it makes design sense?
Another option would be to scrap the base class and just maintain lists of the specific Flyweight objects, but that might be unnecessarily messy.

3. When it comes to keeping track of objects (such as lists of Enemies or Projectiles that must refer to every object of that type in order to properly determine collisions etc.), how should a Factory come into play? I figure an obvious step is to add an Entity to the appropriate list after creation, but how much should the Factory be involved?
Would it be a bad idea to let the Factory manage the lists and instead maybe have a separate "GameWorld" class that deals with such Entity management?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!