can an animation frame trigger another animation? (SOLVED)

Started by EnterTheStory (aka tolworthy), Sat 02/02/2008 12:03:45

Previous topic - Next topic

EnterTheStory (aka tolworthy)

I have a number of characters who fire guns.
At the frame where the gun fires I trigger a sound (e.g. "bang!") but also need to trigger an animation (a puff of smoke)? These are old fashioned guns so the smoke is important.

What I've tried so far:
1. Just incorporating the smoke into each animation. Bad idea. The gunsmoke animation has many large frames (so the smoke spreads out smoothly) so it greatly increases the file size of each sprite. 

2. Creating a new gunsmoke view for each character (using the same images, so there is no impact on file size).  Character views typically have 10 frames (with variable speeds) and the gunsmoke loop has about 50 frames. Both need to be sybnchronized over many repeated loops, and I need to often change their speed. Extremely time consuming.

3. Have a "run always" function to always check if a gun was on screen, and make some calculations for when the smoke is likely to be needed. Again this is time consuming and clumsy, as there may be several guns on screen at once. I can't see how this would work without endless tweaking.

Any other ideas?

Radiant

What I would do is this:

create a separate animation for the smoke, that starts with several blank frames (that can be 1x1 pixel in size).

Start this animation at the exact same time as the gun firing loop is triggered.

EnterTheStory (aka tolworthy)

Quote from: Radiant on Sat 02/02/2008 12:10:53
create a separate animation for the smoke, that starts with several blank frames (that can be 1x1 pixel in size).

Start this animation at the exact same time as the gun firing loop is triggered.

Thanks. That was option 2 or my 3 options. I will probably have to do that. But it will be very time consuming. Each gunsmoke animation is 50 frames, the timing is totally different from the character animations (the smoke moves smoothly, the people often pause). And whenever I tweak a character animation I'll need to recalculate the timing of the smoke. Finally, if there is the slightest difference in timing this will be amplified in every loop. It will be a time consuming fudge, but maybe this is the best I can hope for.

Ghost

You can also, in a room's repeatedly_execute, check if an animation has reached a certain frame, and then call code from there. Would be a bit of a resource hog attempt, but works.

Radiant

Quote from: tolworthy on Sat 02/02/2008 22:15:28
Finally, if there is the slightest difference in timing this will be amplified in every loop. It will be a time consuming fudge, but maybe this is the best I can hope for.

It won't have to be amplified - simply start both animations at the same time, always, that way errors will remain constant rather than variable.

EnterTheStory (aka tolworthy)

Quote from: Ghost on Sat 02/02/2008 22:35:03
You can also, in a room's repeatedly_execute, check if an animation has reached a certain frame, and then call code from there. Would be a bit of a resource hog attempt, but works.

I didn't know you could do that. This sounds interesting, I'll try to find the name of the function. Thanks.

Quote from: Radiant on Sat 02/02/2008 23:21:02
simply start both animations at the same time, always, that way errors will remain constant rather than variable.

My concern is that a character might fire his gun every 20 seconds, so any errors will accumulate. Of course, I may be completely misunderstanding how AGS works here. If two processes run at the same time, and one of them needs a huge amount of code in a single frame, I am assuming this it would slip behind the other process?

Radiant

Quote from: Ghost on Sat 02/02/2008 22:35:03
My concern is that a character might fire his gun every 20 seconds, so any errors will accumulate. Of course, I may be completely misunderstanding how AGS works here. If two processes run at the same time, and one of them needs a huge amount of code in a single frame, I am assuming this it would slip behind the other process?

For starters, I don't think that what you're doing really counts as a "huge" amount of code (specifically, how many thousands of lines is that code? Because AGS wouldn't have problems with 1000-2000 lines). Also, "once per 20 seconds" isn't all that often, considering you can do things 40 times in a single second.

And second, AGS doesn't really have multiple processes. The inner logic works something like this:
Code: ags

  while (user_has_not_quit) {
    if (mouse_clicked_or_moved) handle_mouse ();
    if (key_pressed) call_on_key_press ();
    if (not_paused) {
      move_characters ();
      call_repeatedly_execute ();
    }
    call_repeatedly_execute_always ();
    update_screen ();
  }


Well, it's more complex than that, of course. But the point is that if any part of your code takes up more time, the others will wait, not get thrown out of sync.

EnterTheStory (aka tolworthy)

#7
Thanks. That's good to know.

Meanwhile I intend to experiment with 'character.frame' property. It looks like I can create a general purpose 'run always' function that will only be called when a certain flag is up, and then allow me to trigger any event based on any frame in any animation. That was what I was hoping for, so if I get it working I'll mark this thread as solved. Unless anyone has an even simpler solution.

Thanks again for the feedback.

Edit:

I tried it and it works! Thanks for the suggestions.

SMF spam blocked by CleanTalk