How do I stop a animation from looping?

0 favourites
From the Asset Store
6 looping tracks to use in your games and projects. These tracks are in the style of the 1960s detective movie genre.
  • Hi!

    I'm really new to Construct 2, and I have a question about how to stop an animation from continuing to loop.

    I know that if I click on the animation I want and go to the sidebar I can change the Loop option to NO, but that did not solve the problem.

    And when I try to stop the animation by force, using something like 'Set animation frame to', the animation keeps trying to repeat anyway, and a kind of visual bug happens

    Anyway, here is a print showing the part where I change the animation, I hope you can help me.

    I'd like to do just the animation of Death stop looping.

    Although the animations of the heart being destroyed also do not stop repeating, then I resolved leaving them invisible after the animation ends. But if you have any solution for hearts too, I would be grateful!

    And if I forgot any information, please let me know so I can update the post.

    (btw, english is not my mother tongue, so sorry for the mistakes)

  • juniorasmj

    Once any of your events meet the conditions will be always true unless it becomes false, to avoid this as you wanna change the animations once you will need to an extra condition "Trigger once While true" that will make the event trigger once only also set the animation loop to no on the sprite animation properties

    Another thing the four first events is the same thing repeated four times you could do something like

    -Health is <= 4

    -Add One more condition: Health is => 1

    -Trigger once while true

    >>>>>>>>>>>>>>>>>>>>>>>>Then your Actions

    Else

    Health is <= 0 :

    -Trigger once while true:>>>>>>> your actions + set Health to = 0

  • I started replying, then got distracted and tarek2 beat me

    Yeah, the problem is that all these events are executed on every tick (unless they are sub-events under some parent event, it's not clear from the screenshot).

    If these events are top-level, this means that the animation is restarted again and again on every tick and lots of "wait 1.83" threads are created... It could be a total mess.

    You need to use Else:

    Health=4

    Else Health=3

    Else Health=2

    etc.

    Otherwise when health is for example 1, all four top events are triggered.

    Or add another condition - check if animation is playing:

    Health<=4

    (and) Heart5 is "HeartDestroy" is NOT playing

    Alive=0 condition is also triggered many times and restarting the animation...

    You can add "Trigger once while true" to it or set alive= -1, to prevent if from triggering again.

    Also, don't use long-running "Wait" actions, you don't have control over them. Use Timer behavior.

  • tarek2

    dop2000

    Oh, thank you so much guys! I managed to fix it

    Here is what I've changed:

    Now that I've managed to fix it, another problem has arisen.

    Should I create a different post for it? It has to do with animation as well.

    In any case, I'll explain what the problem is, and in case I need to create another post, I'll do it.

    It turns out that in the game I'm creating, the player can use a sort of leap forward; a tumble.

    Here's how it was programmed:

    In this case, it is a forward jump, where the player will always go to the side he is looking at. (It's a top-down shooter)

    I do not know if there are better and more optimized ways to do this, but if there is another way and you want to share, I really appreciate it.

    So the problem is that if the character dies during the jump, the Death animation is replaced by the Idle animation(or the first frame of Death animation, I'm not sure). And as I've programmed to disable Tumble and PlayerMovement when life reaches 0, the character stands still with that frame goin on.

    Again, if there is any information I can pass to make it easier to get to the solution, just say and I will update the post.

    Anyway, thanks for everyone's help so far!

    And again, english is not my mother tongue (or mother languague, idk), so sorry for the mistakes.

  • The 'wait x seconds' is so powerful for creating long event blocks for beginners but it looks like it is time for you to graduate and start using functions instead.

    The problem is exactly as you have said, once that event runs - conditions can change but since the event block has already started it wont stop and can cause all sorts of issues (I know this from experience, my first game was a mess and insane to debug ).

    'Functions' are events that sit there until they are called into action (using the call function action). Whenever you want to use the wait X, instead of simply adding more events to the chain afterwards we can call a function instead. The major benefit of this is that when that function is called we can once again check with new conditions.

    So, after the wait 0.9 seconds - we call the function 'tumble idle' or whatever you want to call it and part of the condition is that the player's life is >0. If it is not then the function wont run and wont bug your project in the process.

  • juniorasmj

    Your Welcome

    juniorasmj One thing I can understand why you like to create extra events, is it really necessary?

    Since you did the same set up again every "Health Check" separate on his own Event I take it as you wanna do

    -Every 1 Health substracted then Play destroy animation for a specific Heart Right?

    So if you insist on doing it on separate Events dop2000 give you the best solution use "Else" so you can skip all the events bellow once one of the (Health events check) is true and save extra checkings

    But why not do it even simpler

    you must have a (trigger Event) where you subtract the Health

    Example say the Trigger Event is : bullet on collision with Player >>> subtract 1 from Health

    Then why not Run all the Logic under that Trigger so all the Health checks run only if is necessary

    Example Capx:

    https://www.dropbox.com/s/xfitbgehdm5p220/StopAnimationLoop1.capx?dl=0

    Also, use Timers as Doop200 recommended other ways you will keep having Problems that you cannot Debug, you have so many waits there

    Even the Hearts Probably you can combine all of them in one instead of having 5 separates ones

  • Thanks for the help! I understood that the functions are important, I think I will redo the whole game, because I went wrong in several parts. Although they are working, everything I've done so far seems super wrong, hahaha

    tarek2

    Thanks again for the answer! You are awesome!

    So, I opened the file you sent, and it's exactly what I want to do! But I did not understand many things, could you explain them to me? I feel like they are SUPER basic stuff, I'll understand if you'd rather not answer me, it's totally okay!

    Seriously, I have MANY questions, and I can see that they are really simple. So it's completely cool if you do not want to answer! For real!

    I'm going to send out a print pointing out the parts I did not understand and explain them right away.

    So here we go:

    1. Ok, I started using Construct 2 a couple weeks ago, but I feel like I should already understand this, it seems VERY simple. So, my question here is: Will the 'on collision with Player' event only start if Life is greater than 0? If not, I can not understand why line 2 is there.

    2. Why is there nothing here? How did you make for line 3 go down that way? I can not understand what this is T_T

    3. You're just checking if the Frame value is the same as Player.Health, right? And if it is, it will perform the actions. But for example, if the value is the same, how do I know which heart it will run the Destroyed animation?

    4. This Else refers to what? I can not understand these events one underneath the other T_T I feel I need to see a basic video of Construct 2, if you can recommend something, I'm listening.

    5. I did not know the Timers until then, but from what I understood, they make a Counter start, right?

    6. This question is related to 5. In the 5. you put to start Timer 'Hide_Heart' (this is a name that was just quoted here, right? Or do you need to create this before as a variable or something?) And you put it to count 1.83 seconds. Ok, so far I understood, if what I said is right.

    Then at 6. you made the Heart (ON Timer 'Hide_Heart') go to Invisible. Does this mean that DURING the 1.83s the heart will become invisible? Or AFTER the 1.83seconds?

    And from what I understood, that line 6 is like a 'function' then? There are actions inside it that will only happen when I start the Timer X

    7. Why exactly is the player's life going to 0 here? I could not understand

    8. And finally, why is this whole part empty? The same happens just below 6.

    And again, english is not my mother language, so, sorry for the mistakes T-T

    Many thanks to you guys!

  • juniorasmj

    Your Welcome m8, I'm glad to help

    1-The short answer is No

    Let's go back the Basics:

    Construc2 Runs the Events from top to bottom

    Now you have "Top Events" and you have "SubEvents"

    "Top Events" = To the First Event where all the action starts, it can have many conditions, here is where you Start the Picking for the (Objects or Variables, etc...) to who you want to apply your Actions.

    As longs as the Conditions are true it will always run their actions plus any subevents.

    Just to make sure you follow me I'm gonna point you the Top Events from the "Capx example" that I gave you

    Event: (1, 6, 8, 11, 12) are all Top Events the ones with Green Arrow are "Triggers" by the way which means they run once only when they trigger, but for now, lets refer to them as top events

    So now as for your question (Bullet On collision with Player) has just one condition if is true will always Trigger & Run his actions and subEvents

    "SubEvents" = is an Event under the rule of the "Top Event" ins the name SubEvent.

    Now these works different, the subEvents will Never run unless the "Top Event" runs.

    so is like saying

    -Unless the bullet hit the player the subEvents (2 & 4) will never be checked

    -Unless event (6) Triggers SubEvent(7) will never be checked

    -Unless (8) Triggers SubEvent(9) will never be checked

    SubEvents have many benefits example to help you filter more the Picking into a different Groups, another one is to help organise your Events and structures so your code becomes easier and simple to understand, plus probably more things that I cant remember

    ======================================================================

    2-Here we have two things going on

    -The first you need to understand that I would like to use and Else as you can see on SubEvent 4 to separate the logic into two categories

    -The first category = equal to if the Health is (equal or greater) than 1 then run these Actions and subEvents

    -Else = if the Health is lower than 1 then Run these actions and subevents instead

    so I have to separate the event 2 from 3 because other ways if I put them together it can mess up the Else on event 4 also is to help me understand the events much quicker because the else is related to the player's Health not to the Hearts so it makes sense to separate event 2 from 3

    So the answer why event 2 has no actions is empty because I use it just to filter players health is => than 1 so I can use the else on event 4

    =======================================================================

    3-Here "Frame" is an Instance Variable of Hearts be careful don't confuse it with the hearts "Animation Frame" you can change the name to a different one if you wish if you think it will confuse you.

    you can do this by clicking on each heart and on the left properties panel look for the section that says "Instance Variables" there you will find one Variable which is "Frame" you can change it to your needs.

    Also there you can see the Values of the hearts example

    You have 5 hearts

    Heart "Frame" = 4

    Heart "Frame" = 3

    Heart "Frame" = 2

    Heart "Frame" = 1

    Heart "Frame" = 0

    So in event 3 or 5 when we ask if heart "Frame" = to players Health it will Pick the heart that has "Frame" = players health

    Example

    Players health = 1

    sub event will pick only the Heart "Frame" = 1

    That's how c2 knows wich heart to Pick as we don't have any two hearts with the same value there is no confusion

    ====================================================================

    4-I explained it on the answer 2

    ====================================================================

    5-Yes, Timers has many benefits, one is to replicate what you were trying to do with the "waits" but the difference is that

    -Timers Are independents to the object or instances that are calling them

    if an object calls a Timer for 2 seconds then the Actions will not trigger until the Timer stops

    Example:

    Event 3 Picks the right heart and starts the Timer for 1.83

    on Timer ended then >>>event 6 will trigger and Pick the heart who called the Timer

    ==============================================================

    6-AFTER the 1.83seconds the Event 6 Triggers and run their Actions

    -you create and you can choose any name you like but make sure you put the exact name when you call the Timer as when you call the Trigger

    example

    event 3 and event 6 both reference the same Name "Hide_Heart" so they are linked

    -Yes event 6 will only Run if you call the Timer first like in event 3 or 5

    ===============================================================

    7-Normally most of the games they link Players Health with the HUD display, where they show the players Health like I did with the Txt object on the screen showing the Health.

    Now I don't know if it will happen in your game but there is the possibility that example 20 Bullets hit the Player at the same time and if the player was already Health = 1 then it should go down to -19

    making the HUD health looking -19 which is weird at list I didn't see it yet on any Game Health going down less than 0

    So the short answer is to limit and reset Health so it doesn't go under -0

    ====================================================================

    8-When you leave an event empty it becomes like "Every Thick"

    -So the Event reads like >>>Every thick update the Txt to display Health

    Note this part is just for debugging where I like to use Txt and update every thick but you should know that this way is very Cpu demanding and is not the correct way of doing it if you wanna display on an exported Game

    The correct way will be to use

    -Sprite Fonts

    -Update the Txt only when you need it, example you could delete event 8 and just update the Txt on event 1 because is when we manipulate the Health, I didn't do it because I didn't want to add more actions there to confuse I prefer to leave them clean just the action related to the event to avoid any confusion

    I hope I clarified all your questions

    Special recommendation for you to check Asap

    https://www.scirra.com/manual/75/how-events-work

    https://www.scirra.com/manual/167/timer

    https://www.scirra.com/manual/134/performance-tips

    https://www.scirra.com/blog/83/optimisation-dont-waste-your-time

    https://www.scirra.com/manual/73/instance-variables

    https://www.scirra.com/tutorials/253/how-to-make-a-platform-game

    https://www.scirra.com/tutorials/243/building-a-platform-game-a-beginners-guide

  • tarek2

    Thank you very much again!

    I'll read everything you've explained and read the content of the links! This helps a lot!

    After understanding everything, I will redo the game completely, after all, I had not done much until now xD

    And when I finish the game, if you want, I can send a link to the game.

    It's really simple, it's a different version of Ghost Shooter, but with an archer and monsters for him to kill, and I did pretty cool animations of just about everything (at least I think they're cool hahah), actually I'm just doing it to understand how Construct 2 works, to be able to apply what I learned in a more complete and nice game.

  • tarek2

    I'm at this very moment trying to redo the game, but I've encountered a problem.

    I did the same way you did in the example, in regards to the hearts disappearing. But here something is happening that I do not know how to fix.

    Whenever I lose 1 life, the heart (frame = 4) begins the animation of being destroyed, but it keeps repeating itself until I lose 1 more life, so it becomes invisible. And so, the heart (frame = 3) stays the same way, repeating the animation until the next life is subtracted.

    The strange thing is that I put the 'HeartHide' Timer with 2 seconds, and in the On HeartHide Timer I put it to leave the heart invisible, so I'm not really finding the solution.

    Here is a print:

    Sorry for the english and for asking one thing you've already explained :/

    Oh, and by the way, here's the link so you can test the game and understand what I'm talking about: juniorasmj.itch.io/ghost-archer-122

    The password is: asmj

    The controls are: WASD(Walk), Left Click(Shot), Space (Tumble) and F (show and hide the FPS). I put only 1 enemy, but for you to keep losing life, just keep following him with Tumble or something, I left him very slow to be able to test.

  • tarek2

    Btw , I found a solution, but I only managed using System Wait X seconds, as in the print below:

    Using the timer is not working

  • tarek2

    Thank you very much again!

    I'll read everything you've explained and read the content of the links! This helps a lot!

    After understanding everything, I will redo the game completely, after all, I had not done much until now xD

    And when I finish the game, if you want, I can send a link to the game.

    It's really simple, it's a different version of Ghost Shooter, but with an archer and monsters for him to kill, and I did pretty cool animations of just about everything (at least I think they're cool hahah), actually I'm just doing it to understand how Construct 2 works, to be able to apply what I learned in a more complete and nice game.

    Your Welcome m8

    Sure I would love to test it and see what you come up, the Game it sounds a really cool idea

  • tarek2

    I'm at this very moment trying to redo the game, but I've encountered a problem.

    I did the same way you did in the example, in regards to the hearts disappearing. But here something is happening that I do not know how to fix.

    Whenever I lose 1 life, the heart (frame = 4) begins the animation of being destroyed, but it keeps repeating itself until I lose 1 more life, so it becomes invisible. And so, the heart (frame = 3) stays the same way, repeating the animation until the next life is subtracted.

    The strange thing is that I put the 'HeartHide' Timer with 2 seconds, and in the On HeartHide Timer I put it to leave the heart invisible, so I'm not really finding the solution.

    Here is a print:

    Sorry for the english and for asking one thing you've already explained :/

    Oh, and by the way, here's the link so you can test the game and understand what I'm talking about: https://juniorasmj.itch.io/ghost-archer-122

    The password is: asmj

    The controls are: WASD(Walk), Left Click(Shot), Space (Tumble) and F (show and hide the FPS). I put only 1 enemy, but for you to keep losing life, just keep following him with Tumble or something, I left him very slow to be able to test.

    That's the last question I would spect you not to ask me, since we discuss it extensively on this thread by two persons, me personally on my first post I explained and Doop2000 also explained the same thing so that's why you need a few lashing <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    [quote:30t4y8lt]I did the same way you did in the example

    Not Exactly, yes you use the same Method but you placed them separately Making event 30 the Top Event which is fine if you wanna do it that way but you forgot to put something there if you wanna do it that way.

    If you read the Replays 1 & 2 of this thread you would have found the solution really quick to why is behaving that way or if you had followed exactly the example of my capx you wouldn't have that problem, this means after all this talking you still don't understand the difference between an Event that is "Trigger once" or "Every thick".

    [quote:30t4y8lt]Oh, and by the way, here's the link so you can test the game and understand what I'm talking about: https://juniorasmj.itch.io/ghost-archer-122

    The password is: asmj

    Your game looks Really cool keep up the good work <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile"> I like the Graphics and the archer Games I'm sure you gonna do a great Game

  • tarek2

    Btw , I found a solution, but I only managed using System Wait X seconds, as in the print below:

    Using the timer is not working

    Why would work with the "Wait" and not with the "Timer" since they both star a timer for a 1.83sec?

    Here is something to think about it

    Most Devices check 60 Times a second, so this means C2 Checks all your events 60 Times a second

    Now when you have an Event like event 30 which has a condition "Health Is > Grater than 0" and your Player starts with Health = 5 is this event true or False??

    obviously true will be true as longs as the Health is Grater than 0

    So Event 30 is asking if "Health Is > Grater than 0" the Run Event 31

    >>Event 31 is asking is there any "Heart" that match the Instance Variable "Frame" to the Players "Health" ???

    If yes >>>

    Set animation to Break

    Active a timer for 1.83

    Then set invisible

    Now so far good

    Enemy on Collision with Player subtract 1 to Health >>>> Health is now = 4

    Let's analyse your events

    C2 Checks all your events 60 Times a second

    -Event 30 "Health Is > Grater than 0" >>>> yes

    is there any "Heart" that match the Instance Variable "Frame" to the Players "Health"?? >>>>Yes

    Actions:

    Set animation to Break

    Active a timer for 1.83

    Then set invisible

    Question:

    How long can pass until the Enemy collides with Player again? can be anything 1 second or 20sec or 10 Minutes or even 1 hour

    Now let's choose just the lowest 20 seconds, so the player is health = 4 and it didn't collide with the enemy for 20 seconds

    Let's analyse your events

    C2 Checks all your events 60 Times a second

    -Event 30 "Health Is > Grater than 0" >>>> yes

    is there any "Heart" that match the Instance Variable "Frame" to the Players "Health"?? >>>>Yes

    Actions:

    Set (20x60) = 1200 times >>> animation to Break

    Start (20x60) = 1200 times >>> a timer for 1.83

    Set (20x60) = 1200 times >>> To invisible

    And if it didn't collide for 10 minutes?

    60 x 10 = 600

    600 x 60 = 36.000 Times

    Actions:

    Set 36.000 times >>> animation to Break

    Start 36.000 times >>> a timer for 1.83

    Set 36.000 times >>> To invisible

    The poor Heart I think will quite the Gaming Job once for all

    Can you see any problem here? is all explained in post 1 & 2, I gave you the link for "how events work", also check what is the difference between an event that "Triggers Once" and the One that Runs "Every Thick" which is = 60 times A sec

    Take your Time to understand this and many more things, don't rush, is better to spend a few days or weeks understanding this than Rush and after to have to restart the project from the beginning Plus spending Time understanding those things

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Exact! It was my fault. You guys had already explained everything and I was going to the same mistake again.

    So yesterday I had been able to figure out what was wrong and what I could do to fix it. But I just forgot to update the post, sorry!

    Now the action will only happen when the character collides with the enemy, in the way it should be <img src="{SMILIES_PATH}/icon_razz.gif" alt=":P" title="Razz" />

    Here's what I did:

    And I had to make some modifications to the "Boss" because it deals 2 damage.

    In this way:

    and here are the timers that were used:

    I believe everything is working the right way now, you can test the game here: juniorasmj.itch.io/ghost-archer-017

    The password remains the same: asmj

    Now the game is playable, the monsters are at the right speeds and are generated from time to time.

    And the commands also remain the same, but now you can restart the game anytime you want.

    WASD (walking)

    Space (leap / tumble)

    F (show and hide FPS)

    J (restart the game)

    Sorry to bother you so often with something so simple, I promise I'll try my best before coming to the forum again :b

    THANK YOU for the help so far, really! You are awesome.

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