//============================================================================= // PD_QueueAnimationMove.js //============================================================================= /*: * @plugindesc Add Tween Animation. * @author Shio_inu * * @help * last update : 21st dec 2015 v1.0 */ /*:ja * @plugindesc SpriteにTweenアニメーション機能を追加します。 * @author しおいぬ * * @help * last update : 2015/12/21 v1.0 */ //============================================================================= // QueueAnimation.js //============================================================================= /*: * @plugindesc SpriteやWindowにアニメーション機能を追加。 * @author Shio_inu,Thirop * * @help * このプラグインはShio_inu様のPD_QueueAnimationMove.jsを改変したものです。 * 利用につきましてはShio_inu様の配布素材利用規約を遵守下さい。 * 公開元:http://pixeldog.x.fc2.com/material_script.html * */ /*:ja * @plugindesc SpriteやWindowにアニメーション機能を追加。 * @author しおいぬ,シロップ * * @help * このプラグインはしおいぬ様のPD_QueueAnimationMove.jsを改変したものです。 * 利用につきましてはしおいぬ様の配布素材利用規約を遵守下さい。 * 公開元:http://pixeldog.x.fc2.com/material_script.html * */ //============================================================================= var Imported = Imported || {}; Imported.QueueAnimation = true; function QueueAnimation(){ this.initialize.apply(this, arguments); } QueueAnimation.CURVE_EASE_IN_OUT = 0; QueueAnimation.CURVE_EASE_IN = 1; QueueAnimation.CURVE_EASE_OUT = 2; QueueAnimation.UNIFORM = 3; QueueAnimation.DST_ABSOLUTE = 0; QueueAnimation.DST_RELATIVE = 1; function QueueAnimationWait(){ this.initialize.apply(this, arguments); } function QueueAnimationRemove(){ this.initialize.apply(this, arguments); } function QueueAnimationHandler(){ this.initialize.apply(this, arguments); } function QueueAnimationSet(){ this.initialize.apply(this, arguments); } function QueueAnimationMove() { this.initialize.apply(this, arguments); } function QueueAnimationScale(){ this.initialize.apply(this, arguments); } function QueueAnimationRotation(){ this.initialize.apply(this, arguments); } function QueueAnimationOpacity(){ this.initialize.apply(this, arguments); } function QueueAnimationFrameSize(){ this.initialize.apply(this, arguments); } function QueueAnimationSequence(){ this.initialize.apply(this, arguments); } //custom function QueueAnimationVibrate(){ this.initialize.apply(this, arguments); } (function(){ function supplement(default_value, opt_arg, opt_callback) { if (opt_arg === undefined) { return default_value; } if (opt_callback === undefined) { return opt_arg; } return opt_callback(default_value, opt_arg); } function supplementNum(default_value, opt_arg, opt_callback) { return Number(supplement(default_value,opt_arg,opt_callback)); } //============================================================================= // QueuAnimationBase //============================================================================= QueueAnimation.prototype.initialize = function(frame,curveType) { frame = supplement(0,frame); this._frameMax = Math.floor(frame); this._frame = 0; this._curveType = supplement(QueueAnimation.UNIFORM, curveType); }; QueueAnimation.prototype.isStarted = function(){ return (this._frame !== 0)? true : false; }; QueueAnimation.prototype.isEnd = function(){ return (this._frame >= this._frameMax) ? true : false; }; QueueAnimation.prototype.update = function(parent){ this._frame ++; }; QueueAnimation.prototype.frameRate = function(){ // 今どのくらい進んでるかを計算 var framePer = this._frame / parseFloat(this._frameMax); var per = 0; // 元座標と移動先座標の何%の位置に配置されるかを計算 switch(this._curveType){ case QueueAnimation.CURVE_EASE_IN_OUT : if(framePer > 0.5){ per = 0.5 + (Math.sin(Math.PI * (framePer - 0.5)) * 0.5); } else { per = (Math.sin(Math.PI * (-0.5 + framePer)) + 1) * 0.5; } break; case QueueAnimation.CURVE_EASE_IN : per = Math.sin(Math.PI * (-0.5 + (framePer / 2))) + 1; break; case QueueAnimation.CURVE_EASE_OUT : per = Math.sin(Math.PI / 2 * framePer); break; case QueueAnimation.UNIFORM : per = framePer; break; default : per = framePer; break; } return per; }; QueueAnimation.prototype.start = function(parent){ this._isStarted = true; }; QueueAnimation.prototype.reset = function(){ this._frame = 0; this._isStarted = false; }; //============================================================================= // QueueAnimationWait //============================================================================= QueueAnimationWait.prototype = Object.create(QueueAnimation.prototype); QueueAnimationWait.prototype.constructor = QueueAnimationWait; QueueAnimationWait.prototype.initialize = function() { QueueAnimation.prototype.initialize.apply(this,arguments); }; //============================================================================= // QueueAnimationHandler //============================================================================= QueueAnimationHandler.prototype = Object.create(QueueAnimation.prototype); QueueAnimationHandler.prototype.constructor = QueueAnimationHandler; QueueAnimationHandler.prototype.initialize = function(handler,wait) { wait = supplement(0,wait); QueueAnimation.prototype.initialize.call(this,wait); this._handler = handler; }; QueueAnimationHandler.prototype.update = function(parent){ QueueAnimation.prototype.update.call(this,parent); if(this.isEnd() && this._handler){ this._handler(); this.releaseHandler(); } }; QueueAnimationHandler.prototype.releaseHandler = function(){ this._handler = null; }; //============================================================================= // QueueAnimationRemove //============================================================================= QueueAnimationRemove.prototype = Object.create(QueueAnimation.prototype); QueueAnimationRemove.prototype.constructor = QueueAnimationRemove; QueueAnimationRemove.prototype.initialize = function(wait) { QueueAnimation.prototype.initialize.call(this,wait); }; QueueAnimationRemove.prototype.update = function(parent){ QueueAnimation.prototype.update.call(this,parent); if(this.isEnd()){ if(parent.parent){ parent.parent.removeChild(parent); } } }; //============================================================================= // QueueAnimationSet //============================================================================= QueueAnimationSet.prototype = Object.create(QueueAnimation.prototype); QueueAnimationSet.prototype.constructor = QueueAnimationSet; QueueAnimationSet.prototype.initialize = function(animations) { this._animations = animations; this._isStarted = false; this._isEnd = false; }; QueueAnimationSet.prototype.update = function(parent){ if(this._isEnd)return ; var length = this._animations.length; var isEnd = true; for(var i=length-1; i>=0; i--){ var animation = this._animations[i]; if(!animation.isEnd()){ animation.update(parent); } if(!animation.isEnd()){ isEnd = false; } } this._isEnd = isEnd; }; QueueAnimationSet.prototype.isEnd = function(){ return this._isEnd; }; QueueAnimationSet.prototype.reset = function(){ this._animations.forEach(function(animation){ animation.reset(); }); this._isStarted = false; this._isEnd = false; }; QueueAnimationSet.prototype.start = function(parent){ this._isStarted = true; var length = this._animations.length; for(var i=0; i=0; i-=1){ animation = stack[i]; if(animation instanceof QueueAnimationWait){ stack.remove(animation); } } }; Sprite.prototype.removeNonWaitAnimation = function(){ if(!this._animationStack){ this._animationStack = []; } var stack = this._animationStack; var length = stack.length; var animation; for(var i=length-1; i>=0; i-=1){ animation = stack[i]; if(!(animation instanceof QueueAnimationWait)){ stack.remove(animation); } } }; Sprite.prototype.clearAnimations = function() { if(this._animationStack){ this._animationStack.forEach(function(animation){ if(animation.releaseHandler){ animation.releaseHandler(); } }); } this._animationStack = []; }; Sprite.prototype.hasQueueAnimation = function() { return (this._animationStack&&this._animationStack.length>0); }; Sprite.prototype.updateAnimations = function(){ var stack = this._animationStack; if(stack && stack.length !== 0){ if(!stack[0].isStarted()){ stack[0].start(this); } stack[0].update(this); if(stack[0].isEnd()){ stack.shift(); } } }; var _Sprite_update = Sprite.prototype.update; Sprite.prototype.update = function(update) { this.updateAnimations(); _Sprite_update.call(this); }; //----------------------------------------------------------------------------- // Window // Window.prototype.addAnimation = Sprite.prototype.addAnimation; Window.prototype.removeWaitAnimation = Sprite.prototype.removeWaitAnimation; Window.prototype.removeNonWaitAnimation = Sprite.prototype.removeNonWaitAnimation; Window.prototype.clearAnimations = Sprite.prototype.clearAnimations; Window.prototype.hasQueueAnimation = Sprite.prototype.hasQueueAnimation; Window.prototype.updateAnimations = Sprite.prototype.updateAnimations; var _Window_update = Window.prototype.update; Window.prototype.update = function() { this.updateAnimations(); _Window_update.call(this); }; })();