I want to make two sprites to gradually appear after that a group of sprites are destroyed.

  • Greeting Construct 2 users,

    I want to make two sprites gradually appear in my layout, by increasing their opacity value after that a group of sprites are destroyed. The picture below is showing the code that I have included in my project to make that happen. However, it doesn't work, and I need help to make it work, thank you.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi, to begin with, did you make sure that all the conditions are met so the sub events can run?

  • To Tomycase:

    Yes, when I test my game, I kill all those sprites and the sub-events are still not working.

  • Okay so, when you say "kill those sprites", you don't destroy them right? They are still somewhere in the layout? Just to be sure

  • To Tomycase:

    Yes, the sprites are destroyed, when their instance variable is equal or inferior to zero they are destroyed (you can't see that in the piece of code displayed in my post but it is programmed somewhere else in my event sheet). What I want to do is this: When their instance variable is equal or inferior to zero and the sprites are all destroyed, the sub-event is supposed to be executed.

  • Well that's the problem, if the instances are destroyed, the program can't check their variables anymore as they're destroyed with the sprites, you would need to turn them invisible instead, but that can become a bit fastidious;

    There are better methods that relay only on triggers instead of loops, give me some time and I'll prepare an example for you ~

    EDIT : before I prepare the example, do you know about loopidex and how to use it?

  • To Tomycase:

    No, I never heard or saw anything named "loopidex" before. What is this? What does it do? what is the purpose of that thing?

    Thank you in advance for the example!

  • I forgot to ask, do you have free version or complete version of Construct 2 ?

  • To Tomycase:

    I have the complete version of Construct 2.

  • Perfect! Here is the example then :

    This is the result I get : i.ibb.co/h7MFhfn/Example.gif

    3 enemies, I destroy them and the face appears gradually with the forcefield;

    This is how I achieved it :

    What I did, is to put all the enemies in a common family, and give a variable named "Activation" to the computer face sprite;

    When a sprite from the enemy family is destroyed, it adds 1 to "Activation"; When this variable reachs the number of enemy you want, it triggers that event once :

    "Wait 1 second > Repeat 4 times : Wait loopindex*(time you want) > opacity+25

    Loopindex represents the index of the current loop, in this event when it repeats 4 times, the first loop index = 0, second loop = 1, third loop = 2; etc (index always starts from 0 unless you use a "For" loop)

    The 4 loops trigger at the same time, but the wait action delay is equal to the loop index multiplied by the number of your choice, which means in the example that the first opacity adjustement triggers at 0*0.5 = 0s, second at 1*0.5 = 0.5s, third at 2*0.5 = 1s, etc;

    That way you have events that rely only on triggers instead of a loops with the result you wanted ^^

    Be careful however if you use that loopindex method to not use it into a looping condition, otherwise it will repeat constantly, it needs to be triggered a single time (with a trigger event or "trigger once while true);

    Btw unrelated but I guess your turrets and cannons works the same right? Because I see that you create two differents objects for each, meaning that you had to duplicate the code for each, when you could diplucate them on layout then mirror the sprites and use a single code, it would simplify things a lot; if you don't know how to do I can help on that too ~

  • To Tomycase:

    I have integrated the code in my Event Sheet and it works! Thank you a lot for your help!

  • No problem! Also try to do as I recommended for your objects that behave the same, your cannons and turrets for example, that will save memory and code ^^

  • To Tomycase:

    Yes, you were right! I am having problems. The game seems to have a bug because I have too much code. Explain to me how to duplicate the sprites on the layout then mirror the sprites and use a single code, to save memory. I thought that it was not very important but now it's causing issues.

    Thank you!

  • To Tomycase:

    Maybe by showing how I have organized the code for the Turrets and the laser cannon, you will be able to tell me what I should delete and conserve to save memory:

    (Note that the Sine Behaviour was applied for the Horizontal Cannon that the reason why there is no code concerning their movement):

  • Okay so, here is what I did for your turret, what I get : i.ibb.co/b7jnDn1/Example2.gif

    How I achieved it :

    I reused the loopindex trick this time to determine which image point to use on the turret (loopindex+1, otherwise it would pick points 0 and 1 instead of 1 and 2)

    For the turret itself I just copy pasted it on the layout and changed the angle of the second one to 180, then I pass the angle to the laser within the event, if laser bullet parameter "set angle" is on, it will automatically change the angle of the sprite without extra actions;

    For your second image I'd need a description of what effect you want to achieve here, because I'm not sure to get it, and also your lasers ray behaviors and parameters;

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