i think option 2 is the better one. to simplify it we can have some sort of variable or function defined in the character clip to change characters
characterClip.setCharacter("pkhead");
characterClip.animation = "walk";
then in the character clip would be multiple frames storing the animations for each character. and the definition of the setCharacter function would be:
this.setCharacter = function(name) {
this.gotoAndStop(name);
}
which is just basically an alias for gotoAndStop
since all setCharacter
does is call this.gotoAndStop
and both functions have the same number of arguments and argument types, so you could probably change it to this
this.setCharacter = this.gotoAndStop;
which would make setCharacter
a useless function, since because of the transitive property of equality you can just do this to set the character clip
characterClip.gotoAndStop("pkhead");
Um anyway. And then in each character frame code would go like this
this.lastAnim = null;
onEvent("update", function() { // this is to show that the following code should be in the update script, you can put it there if you like
if (this.lastAnim !== parent.animation) { // if curr animation playing changed?
this.gotoAndStop(parent.animation);
this.lastAnim = parent.animation;
}
});
Also, I have an idea on how to make option 2 take up more less space. Instead of having two identical clips for the two individual characters, have only one clip and make a separate clone for each character clip. In the controller clip will be a variable referencing its appropriate character clip.
// In the controller clip
this.character = characterClip.clone();
this.character.animation = "none";
(this.character.setCharacter || this.character.gotoAndStop)("pkhead");
// Use setCharacter if it's defined, otherwise use gotoAndStop instead.
// If you want to define a setCharacter function you can use that,
// even though it's going to be exactly the same as the gotoAndStop function.
onEvent("update", function() {
this.character.animation = "none";
if (walking) this.character.animation = "walking";
if (grounded) {
this.character.animation = "idle";
} else {
if (yVel >= 0) this.character.animation = "jumping";
else this.character.animation = "falling";
}
this.character.x = this.x;
this.character.y = this.y;
});
and then add code to delete the character in the unload script