1 decade ago by Joncom
Where ever possible, I try not to write duplicate code. But sometimes I don't see any way around it. Here's an example where I'm not really sure what can be done....
If I could somehow use the value of this.value in the selection of which animation to use, this would clean up real nice.
Anybody know a better way than this?
If I could somehow use the value of this.value in the selection of which animation to use, this would clean up real nice.
Anybody know a better way than this?
moveAnimStart: function(alternateFeet) { switch(this.facing) { case 'left': if(this.speed==this.walkSpeed) { if(this.leftFoot) this.currentAnim = this.anims.walkLeftA; else this.currentAnim = this.anims.walkLeftB; } else // assume he is running { if(this.leftFoot) this.currentAnim = this.anims.runLeftA; else this.currentAnim = this.anims.runLeftB; } break; case 'right': if(this.speed==this.walkSpeed) { if(this.leftFoot) this.currentAnim = this.anims.walkRightA; else this.currentAnim = this.anims.walkRightB; } else // assume he is running { if(this.leftFoot) this.currentAnim = this.anims.runRightA; else this.currentAnim = this.anims.runRightB; } break; case 'up': if(this.speed==this.walkSpeed) { if(this.leftFoot) this.currentAnim = this.anims.walkUpA; else this.currentAnim = this.anims.walkUpB; } else // assume he is running { if(this.leftFoot) this.currentAnim = this.anims.runUpA; else this.currentAnim = this.anims.runUpB; } break; case 'down': if(this.speed==this.walkSpeed) { if(this.leftFoot) this.currentAnim = this.anims.walkDownA; else this.currentAnim = this.anims.walkDownB; } else // assume he is running { if(this.leftFoot) this.currentAnim = this.anims.runDownA; else this.currentAnim = this.anims.runDownB; } break; } if(alternateFeet) this.leftFoot = !this.leftFoot; this.currentAnim.rewind(); },