arcturial's Forum Posts

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

    https://github.com/arcturial/sprite-factory

  • 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.

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't think it's possible to set an expression return type as an object. The only supported return type for "any" is ef_return_any and that only supports int, float and string (according to the documentation.

    However, you can maybe have the expression return an object UID and then use the "Pick by UID" event to return the correct object.

    As for checking the object type. In the expression, you can do a lookup on the UID to find the object type and then you can do an "instanceof cr.plugins_.Sprite" comparison. If that fails you can throw an exception.

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

  • 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.

  • 6 posts