[PLUGIN] Sprite Object Factory

Post your completed addons to share with the community

Post » Sun Oct 20, 2013 12:42 pm

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.
B
3
Posts: 6
Reputation: 187

Post » Mon Oct 21, 2013 3:09 pm

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 :)
B
3
Posts: 5
Reputation: 185

Post » Mon Oct 21, 2013 4:32 pm

Glad I could help, let me know how it turns out.
B
3
Posts: 6
Reputation: 187

Post » Fri Oct 25, 2013 3:14 pm

Thanks for making and sharing, much appreciated ...
B
36
S
10
G
4
Posts: 250
Reputation: 7,963

Post » Sun Oct 27, 2013 7:17 am

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.Kyatric2013-10-27 07:20:16
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
291
S
114
G
95
Posts: 7,293
Reputation: 70,144

Post » Sun Oct 27, 2013 9:44 am

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.
B
3
Posts: 6
Reputation: 187

Post » Mon Oct 28, 2013 10:31 am

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

R146 is only the latest stable release.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
291
S
114
G
95
Posts: 7,293
Reputation: 70,144

Post » Wed Nov 06, 2013 6:29 pm

is there an capx example on this ?
B
13
S
5
G
4
Posts: 176
Reputation: 4,429

Post » Thu Nov 07, 2013 11:20 am

nice, 1+ for an example file
B
80
S
29
G
133
Posts: 211
Reputation: 72,571

Post » Mon Dec 30, 2013 11:02 pm

I added the .capx file to the article (bottom of the article). You can also access it directly here:

Factory.capx

You can switch between factory objects by pressing W and Q and you fire with Space.
B
3
Posts: 6
Reputation: 187

Next

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 2 guests