Advertisement
ezmash

Looping Animations (MV)

Oct 24th, 2015
2,329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Looping Animations
  3. // by Shaz
  4. // Last Updated: 2015.10.30
  5. //
  6. // Revisions:
  7. // 2015.10.30 Allow animations to play below/behind character
  8. //=============================================================================
  9.  
  10. /*:
  11.  * @plugindesc Allows animations on the map to loop
  12.  * Also allows animations (normal or looping) to play below/behind characters
  13.  * @author Shaz
  14.  *
  15.  * @help
  16.  *
  17.  * Plugin Command:
  18.  *   LoopAnim start event animid   # Start a looping animation on an event
  19.  *   LoopAnim stop event           # Stop animation loop
  20.  *
  21.  *   SetAnimLoc event location     # Set location of animation
  22.  *
  23.  *   event = number for specific event
  24.  *   event = 0 for "this" event
  25.  *   event = -1 for player
  26.  *   event = $gameVariables.value(x) to get the event id from variable x
  27.  *
  28.  *   location = below or behind - play animation behind character sprite
  29.  *   location = above or front - play animation in front of character sprite
  30.  *              default is to play animation in front of character sprite
  31.  */
  32.  
  33. (function() {
  34.   var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  35.   Game_Interpreter.prototype.pluginCommand = function(command, args) {
  36.     _Game_Interpreter_pluginCommand.call(this, command, args);
  37.  
  38.     if (command.toUpperCase() === 'LOOPANIM') {
  39.       var character = this.character(eval(args[1]));
  40.       if (character) {
  41.         switch (args[0].toUpperCase()) {
  42.           case 'START':
  43.             character.loopAnimStart(args[2]);
  44.             break;
  45.           case 'STOP':
  46.             character.loopAnimStop();
  47.         }
  48.       }
  49.     }
  50.  
  51.     if (command.toUpperCase() === 'SETANIMLOC') {
  52.       var character = this.character(eval(args[0]));
  53.       if (character) {
  54.         character.setAnimLoc(args[1] || 'above');
  55.       }
  56.     }
  57.   }
  58.  
  59.   var _Game_CharacterBase_initMembers = Game_CharacterBase.prototype.initMembers;
  60.   Game_CharacterBase.prototype.initMembers = function() {
  61.     _Game_CharacterBase_initMembers.call(this);
  62.     this._loopAnimId = 0;
  63.     this._animZ = 8;
  64.   };
  65.  
  66.   Game_CharacterBase.prototype.loopAnimStart = function(animId) {
  67.     this._loopAnimId = animId;
  68.     this.requestAnimation(animId);
  69.   };
  70.  
  71.   Game_CharacterBase.prototype.loopAnimStop = function() {
  72.     this._loopAnimId = 0;
  73.   };
  74.  
  75.   Game_CharacterBase.prototype.setAnimLoc = function(location) {
  76.     switch (location.toUpperCase()) {
  77.       case 'BELOW':
  78.       case 'BEHIND':
  79.         this._animZ = 0;
  80.         break;
  81.       default:
  82.         this._animZ = 8;
  83.     }
  84.   }
  85.  
  86.   Game_CharacterBase.prototype.animZ = function() {
  87.     return this._animZ;
  88.   }
  89.  
  90.   Sprite_Character.prototype.isAnimationPlaying = function() {
  91.     if (this._animationSprites.length > 0) {
  92.       result = true;
  93.     } else if (this._character._loopAnimId > 0) {
  94.       this._character.requestAnimation(this._character._loopAnimId);
  95.       this.setupAnimation();
  96.       this._animationSprites[this._animationSprites.length - 1].z = this._character.animZ();
  97.       result = true;
  98.     } else {
  99.       result = false;
  100.     };
  101.     return result;
  102.   };
  103. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement