This seems to come up with some frequency on the Stencyl forums.
The first assumption that is typically made is to make this “death” code a part of the player actor or whichever actor is being killed. Sometimes this can work; however, this often can pose some messy problems. An actor can have any number of things going on in other behaviors, not to mention outside influences trying to still do things to the actor (gravity, enemies, etc.). The response to such might be to disable behaviors and put other safeguards in place, but this can often become an ugly affair, as your death code will possibly require upkeep as behaviors are added and removed; further, trying to disable all natural outside forces from acting upon your actor can be a hassle too. It’s just opening you up for a lot of error and headache.
So perhaps a better alternative is this: upon death, spawn a special “death actor”.
This is a very effective means, even for simplistic actors. For one, you dump all the baggage of the previous behaviors: no animation conflicts, no movement input, etc. coming from behaviors that aren’t needed anymore (your actor is “dead”, remember). Now, you can stick all the code relative to your death sequence in that particular death actor. Furthermore, you can tweak physics defaults to suit the situation, like giving the death actor a “doodad” collision group instead of trying to manipulate the physics of your regular actor.
Integration into your regular actor is simple too. Something like this:
When Death Happens:
-Spawn Death Actor at Position
-Kill Self
Where death represents some conditional or event injected into your normal actor. Your normal actor dies and the code of the death actor starts.
(Note: creating your death actor with the same size as your regular actor, even if its animation is smaller, is a good idea. It means you can spawn it right at the x/y position of the regular actor.)
So why the separation? Why not make separate “walking actors” or “jumping actors”? The reasoning is simple: we’ve sectioned off two sets of behaviors that aren’t meant to co-exist/run together. Running (the act of normal horizontal movement) and jumping often happen together in a game. On the other hand, when “death” happens, a lot of times everything else is meant to stop as the death sequence commences. Therefore, it makes sense to abandon everything else and give “death” free reign to do as it pleases without pesky interference (or tricks through flaming hoops to bottle up interference in a single actor).
Leave a Reply