[PLUGIN] Sprite Object Factory

0 favourites
  • 11 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • I am creating a platform shooter where the bullet that I fire changes based on some power-ups and so forth. It was getting quite annoying to manage the type of bullet that needs to spawn with sub-events as the statement kept growing.

    I created a new plugin that allows you to spawn a "Factory" object instead. The factory object is aware of the type of object it is representing (in this case, which bullet). So instead of having an elaborate sub-event statement, you always just spawn the "Factory" object and the object in the factory just get's changed depending on which bullet needs to spawn.

    I wrote an article about it explaining how it works. Feel free to go check it out and let me know what you think.

    You can download or contribute to the addon here.

  • I'll definitely be giving this a whirl since it would work well in the tower defense im currently fiddling with. I think you may have just made my life a whole lot easier.. Thanks :)

  • Glad I could help, let me know how it turns out. <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Thanks for making and sharing, much appreciated ...

  • You basically reinvented families. It's a license-only feature, but it pretty much allows you to do what you seem to be looking for.

    It's also possible to make several "families" with a single object type but using several animation frames.

    For example if the modification is mostly visual you can go something like this : example capx.

    I often say, it's nice to make new behavior and stuff, but C2 is already powerful enough to handle a lot with the common/basic system available, and it's often a mistake to try to expand it when it's "easier" to go with what's already in.

    Unless I'm proven wrong and there's something I'm overviewing (which can very well be the case), I'd rather not add this behavior to the list as the basic event/features are already capable of this.

  • The factory wasn't created as an alternative to families, more like an addition. Factories don't group objects of a certain type together and can't group types to respond to certain events like families do.

    The factory is purely a spawning mechanism. Families lack the capability of spawning a specific object inside the family. When you pass a family to a spawn event, it picks a random object in the family to produce. This is what the factory was designed for.

    If you have a gun that can fire 10 different types of bullets. 5 are projectiles and do area of affect damage and the other 5 are "bullets" and do single target damage. You can create two families, "projectile" and "bullet". You can configure events on those families for area of affect explosions and damage distribution and of course the single target behaviour. In order to know which bullet type is currently active in your gun, you would need to have a global variable that keeps track of the UID or instance type. So you need at least 10 events to set the instance type based on the power up you picked up. You need another 10 events of sub conditions to spawn the different type of objects..."if bullet_type == laser1UID, then spawn the laser1 at the gun position".

    The factory makes this easier as your spawn method doesn't have to have 10 sub conditions. You simply say "spawn the factory and the gun position" and then you configure the factory the same way you would the global variable. "When I pick up powerup1, set the factory object to laser1". This means, your factory takes the place of that global variable.

    So the two family types are still very important in order to deliver the right amount of damage and animations. However, the factory makes our event sheet a little easier to manage and it also makes it fairly easy to add more bullet types. You can even throw another bullet family type into the mix without having to change anything in the "spawn" method.

    If you have an easier way of accomplishing this behaviour, feel free to share it. I wrote this plugin because I had a specific need that I couldn't replicate otherwise, but naturally it's possible that I missed something.

    Unfortunately I wasn't able to open your example as it's released in version 148 and I could only find 146 on the website.

  • R148 Beta release you can find a link at the very bottom of this page.

    R146 is only the latest stable release.

  • is there an capx example on this ?

  • nice, 1+ for an example file

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I added the .capx file to the article (bottom of the article). You can also access it directly here:


    You can switch between factory objects by pressing W and Q and you fire with Space.

  • If you run into problems, make sure you have the latest version of the plugin.


Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)