Fade behavior not activating... for no apparent reason?

Post your own tutorials, guides and demos.

Post » Thu Jan 29, 2009 5:40 pm

Attached are two cap files that should do almost exactly the same thing, but don't. Load them up, and click the sprites on screen. (For the "fail" one, click multiple times)

The behavior that SHOULD happen, and does on the "success" file, is that the animation will change to "Dying" and then it will fade away and be destroyed.

On the "fail" file, however, the dying sprite is triggered, but FADE DOES NOT ACTIVATE.

Look at the events for the two files. They are -exactly the same-, the ONLY difference being what triggers the event.

What gives?
B
2
G
3
Posts: 71
Reputation: 992

Post » Thu Jan 29, 2009 5:47 pm

The fade is activating. 'Start fade' makes it rewind to the beginning of the fade and play from there (when it's opaque). The condition 'Variable less than 0' isn't just true once. It's true all the time. The events are checked once every tick (generally 60-100 times per second), so you're repeating the 'start fade' action over and over again.

Add the 'Trigger once' system condition below the condition, and it makes it true only once, even when it repeats. It makes it act like a trigger, so it runs just once the first time it's true, instead of every tick.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,620

Post » Fri Jan 30, 2009 8:37 am

I'm having the same problem, but what I've noticed when I use the Trigger Once condition is that if there are two sprites on the screen (of the same family), only one performs the fade event (or whatever other events), while the other sprite doesn't change at all (animation nor fade). Only until the first sprite is gone is the second sprite able to do what it's supposed to do, but only if it were still "alive" after the first sprite disappeared.

I tried adding "Trigger Once" as a subevent, but it gave me a similar problem.
B
1
G
4
Posts: 6
Reputation: 1,037

Post » Fri Jan 30, 2009 1:41 pm

Can you upload a .cap?
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,620

Post » Fri Jan 30, 2009 5:48 pm

Well, if you're talking to me, I tried to isolate the problem in this cap file. If you run it and kill both zombies (within a second or so of each other), only one will fade. In my original game, when I put the Trigger Once in a subevent along with the fade event, both zombies stopped moving and played their "dead" animation, but still only one faded.
B
1
G
4
Posts: 6
Reputation: 1,037

Post » Fri Jan 30, 2009 6:02 pm

The 'Trigger once' means it won't run the event again if it suddenly becomes true for two objects, instead of one. It just still counts as 'true' overall and won't re-trigger. Use a private variable to mark an object as fading (eg. set 'Is Fading' to 1), and change the event to say:

+ Health < 0
+ Is fading = 0
-> Start fade
-> Set Is fading to 1
...etc.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,620

Post » Fri Jan 30, 2009 7:10 pm

That worked. Thanks.
B
1
G
4
Posts: 6
Reputation: 1,037


Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 0 guests