Play animation on collision. Destroy animation
Hi,
Im having a very frustrating problem. I've got a bullet object, an enemy and an explosion. All of them are active objects. The explosion has got 12 frames in the "stopped".
I've got these events.
- When bullet collides with enemy then shoot an object at speed 0, start animation of explosion.
- When animation explosion stopped then destroy explosion
When I have this last event on then there is no explosion at all. When it's off the explosion won't get away after the last frame animation.
Are there some tutorials about this subject? Or some examples?
Hope to hear from you guys soon.
Maarten
maartennauw.com
Re: Play animation on collision. Destroy animation
Im sorry but I don't know what to do. If I had a copy of your game I could toggle around with it and fix it but I can't put in words how to actually fix it.
Re: Play animation on collision. Destroy animation
I've made a simple scene. You can download it here:
http://www.2shared.com/file/yqWbB-VM/Problem.html
As you can see when you press "Spacebar" the animation plays. And when the animation is stopped it will be destroyed. But when you press space again there is no new object created.
Hope you can help me.
Maarten
Re: Play animation on collision. Destroy animation
A couple things to know:
1. You don't need to "shoot" your explosion object. Just use the "Create" action and set the explosion's position relative to the enemy (when the create dialigue box appears, you can click where the word "relative" is or simply click on the enemy on the stage, if it is visible).
2. The reason the explosion is not appearing is because you told it to destroy that object any time the Stopped animation is playing. Since Stopped is the default animation that is played when you create something, the code is destroying the object before it is even drawn. You can fix this by adding another condition to check for the frame number like so:
+If active(explosion) animation Stopped is playing
+If animation frame = 5 (assuming your animation is 6 frames long. MMF2 starts numbering frames at zero)
- Destroy explosion
Hope that helps,
Mobichan
Re: Play animation on collision. Destroy animation
Thank you very much! It was the "Create object" function that i needed!
Re: Play animation on collision. Destroy animation
Quote:
Originally Posted by mobichan
... Since Stopped is the default animation that is played when you create something, the code is destroying the object before it is even drawn.
Hope you don't mind a small correction ^^;;; The default animation is actually "Appearing", which switches to "Stopped" (or whatever else's defined) automatically unless it is set to loop forever (same as when an object gets destroyed, the "Disappearing" animation automatically kicks in).
Re: Play animation on collision. Destroy animation
The easiest way to do this would be to move what you have as the "Stopped" animation, over to the "Disappearing" animation. If you do this, the object will actually be destroyed automatically when the animation ends, so no events are needed. This is what I always do for my explosions.
There is also the "Has an animation finished?" condition, which has the same effect as what mobichan posted but is slightly easier.
Re: Play animation on collision. Destroy animation
I didn't encourage using the Disappearing animation because any overlapping conditions to detect if the player bullets hit the enemy would continue to register during a disappear animation. I avoid using it for this reason as a matter of habit now.
And I have had issues with "Has animation finished" as well, where if the animation doesn't register (due to a frame skip or something) the object will not continue to register the animation has ended. This means any actions that use "Has animation finished" would not get called.
@RayMarble: Thanks for the correction. :)
Mobichan
Re: Play animation on collision. Destroy animation
Quote:
Originally Posted by mobichan
I didn't encourage using the Disappearing animation because any overlapping conditions to detect if the player bullets hit the enemy would continue to register during a disappear animation. I avoid using it for this reason as a matter of habit now.
Err hm ^^;;; collisions get turned off automatically during the "Disappearing" animation, bullet collision won't get detected. So it's safe :-) I'll make an example later.
(Later) And here's the example with a brief explanation:
http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=213974&#Post213 974
Re: Play animation on collision. Destroy animation
It might be more helpful to see what you are doing rather than a swf. I have definitely run into issues where I do things like add score or create fx (through fastloops) that will trigger the loop mulitple times from "Is overlapping" conditions. But another solution would be to add a negated "Is animation Disappearing playing" condition.
Re: Play animation on collision. Destroy animation
Here you go, I updated the thread. In case you won't be able to open the Unicode file there's also a screenshot of the two events that fuel the experiment, one is
.active 1 collides with active 2
=play sound
.pressed space
=destroy active 1 (rectangle)
Re: Play animation on collision. Destroy animation
Ah, I think my confusion here is due to you using the "obj collides with obj" check, which only returns true once and can be affected by a frame skip (which is why I don't use any overlapping condition besides "Is obj overlapping obj). The "is obj overlapping" is checked every frame and will return true if the overlapping occurs during a Disappearing animation (at least that is how my experience has been).
So, if you do the one time check you are suggesting, the problem I described won't occur. But you might not get your code to fire at all if you miss that frame entirely. :)