Reuse code

0 favourites
  • 10 posts
From the Asset Store
Two levels with two sistem Wave. with Source-code (.c3p) + HTML5 Exported.
  • Hey again

    I have been trying to find an answer to this question, but with 20 scirra tabs open, and trying various search phrases I still am not winning.

    As a normal developer I like to re-use code, create methods by name and then use the method when I want stuff done.

    I haven't found a way to do this yet, and was wondering if there was. The example is that I have 4 unique sprites. But I want them to act the same, respond to the same events and behave the same way. It would be nice to then create events and pass parameters.

    I saw there was a plugin of this sort of nature mentioned, but for the life of me I cant find where I saw it.

    Any suggestions or feedback would be great!

    cheers

  • Try Function plugin

  • Create a family for them (-not in the free I think-) and do the eventing for that.

    One possibility to reuse code is including eventsheets.

  • Family can not be used in free version.

  • Turn the 4 unique sprites into a single one, setting the animation speed to 0 and differentiating each instance with its initial animation frame.

    That would allow to write a bit of code that can affect all 4 instances at the same time (using a loop) or separatly if you need (picking a specific instance).

  • Turn the 4 unique sprites into a single one, setting the animation speed to 0 and differentiating each instance with its initial animation frame.

    That would allow to write a bit of code that can affect all 4 instances at the same time (using a loop) or separatly if you need (picking a specific instance).

    I already use this solution and it work perfectly.

    Just control every common behavior of "enemy" in my game using the same sprite and their different behaviours picking up the animation which they are running (using sub-event is ... animation playing). With this you can control a single instance event if it "trasform" changing it's animation.

    Or you could even control each instance with the id.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Generally, the best ways to reuse code are:

    1. groups which are set active only occasionally

    2. event sheet includes.

  • function, use function :P thats how real coders do it

  • Downloading and trying function.

    Thanks for all the replies. I have a paid version :)

    I'll let you know if I come right!

  • It is working.

    I would love to pass a sprite as a parameter to a function as an object, but I will figure something out.

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