/** @language japanese
* <p>LTweenLiteはアニメーショントゥイーン用ライブラリです。高速・軽量がウリなんです。</p>
* @class LTweenLite
* @constructor
* @since 1.4.0
* @public
*/
var LTweenLiteTimeline;
var LTweenLite = (function () {
function LTweenLiteChild ($target, $duration, $vars) {
var s = this;
LExtends (s, LObject, []);
s.type = "LTweenLiteChild";
s.toNew = [];
s.init($target, $duration, $vars);
}
var p = {
init : function($target, $duration, $vars) {
var s = this, k = null;
if (typeof $vars["tweenTimeline"] == UNDEFINED) {
$vars["tweenTimeline"] = LTweenLite.TYPE_FRAME;
}
s.target = $target;
s.duration = $duration || 0.001;
s.vars = $vars;
s.delay = s.vars.delay || 0;
if(s.vars["tweenTimeline"] == LTweenLite.TYPE_TIMER){
s.currentTime = (new Date()).getTime() / 1000;
s.initTime = s.currentTime;
s.startTime = s.initTime + s.delay;
}else{
s.currentTime = 0;
s.duration *= 1000;
s.currentTime -= s.delay * 1000;
}
s.combinedTimeScale = s.vars.timeScale || 1;
s.active = s.duration == 0 && s.delay == 0;
s.varsto = {};
s.varsfrom = {};
s.stop = false;
if (typeof(s.vars.ease) != "function") {
s.vars.ease = LEasing.None.easeIn;
}
s.ease = s.vars.ease;
delete s.vars.ease;
if (s.vars.onComplete) {
s.onComplete = s.vars.onComplete;
delete s.vars.onComplete;
}
if (s.vars.onUpdate) {
s.onUpdate = s.vars.onUpdate;
delete s.vars.onUpdate;
}
if (s.vars.onStart) {
s.onStart = s.vars.onStart;
delete s.vars.onStart;
}
for (k in s.vars) {
s.varsto[k] = s.vars[k];
s.varsfrom[k] = s.target[k];
}
},
pause : function () {
this.stop = true;
},
resume : function () {
this.stop = false;
},
tween : function () {
var s = this, tweentype;
var type_timer = (s.vars["tweenTimeline"] == LTweenLite.TYPE_TIMER);
if (type_timer) {
var time = (new Date()).getTime() / 1000, etime = time - s.startTime;
if (etime < 0) {
return;
}
} else {
if (s.stop) {
return;
}
s.currentTime += LGlobal.speed;
if (s.currentTime < 0) {
return;
}
}
for (tweentype in s.varsto) {
if (tweentype == "tweenTimeline") {
continue;
}
if (type_timer) {
s.target[tweentype] = s.ease(etime, s.varsfrom[tweentype], s.varsto[tweentype] - s.varsfrom[tweentype], s.duration);
} else {
s.target[tweentype] = s.ease(s.currentTime, s.varsfrom[tweentype], s.varsto[tweentype] - s.varsfrom[tweentype], s.duration);
}
}
if (s.onStart) {
s.onStart(s.target);
delete s.onStart;
}
var e;
if (type_timer) {
e = (etime >= s.duration);
} else {
e = (s.currentTime >= s.duration);
}
if (e) {
for (tweentype in s.varsto) {
s.target[tweentype] = s.varsto[tweentype];
}
if (s.onComplete) {
s.target.target = s.target;
s.target.currentTarget = s;
s.onComplete(s.target);
delete s.target.currentTarget;
delete s.target.target;
}
return true;
} else if (s.onUpdate) {
s.onUpdate(s.target);
}
return false;
},
to : function ($target, $duration, $vars) {
var s = this;
s.toNew.push({target : $target, duration : $duration, vars : $vars});
return s;
},
keep : function () {
var s = this, t, vs, k;
if (s.toNew.length > 0) {
t = s.toNew.shift();
if (t.vars.loop) {
s.loop = true;
}
if (s.loop) {
vs = {};
for (k in t.vars) {
vs[k] = t.vars[k];
}
s.to(t.target, t.duration, vs);
}
s.init(t.target, t.duration, t.vars);
return true;
}
return false;
}
};
for (var k in p) {
LTweenLiteChild.prototype[k] = p[k];
}
function LTweenLite () {
LExtends (this, LObject, []);
this.type = "LTweenLite";
}
LTweenLite.TYPE_FRAME = "type_frame";
LTweenLite.TYPE_TIMER = "type_timer";
p = {
tweens : [],
ll_show : null,
frame : function(){
var s = this;
var i, length = s.tweens.length, t;
for (i = 0; i < length; i++) {
t = s.tweens[i];
if (t && t.tween && t.tween()) {
s.tweens.splice(i, 1);
i--;
length = s.tweens.length;
if (t.keep()) {
s.add(t);
}
}
}
if (s.tweens.length == 0) {
s.ll_show = null;
}
},
/** @language japanese
* [静的]新しい LTweenLiteChild インスタンスを作成して,指定したオブジェクトのある属性を指定した値に変更する。
* @method LTweenLite.to
* @static
* @param {Object} target トゥイーンするオブジェクト
* @param {float} duration 時間
* @param {Object} vars <p>パラメータ。 x,y,onComplete, easeなど. 例えば, オブジェクト mc.x を 100にトゥイーンする 、mc.y を 200にトゥイーンする 、トゥイーンが終わったら myFunction関数を呼び出す, やり方は: TweenLite.to(mc, 1, {x:100, y:200, onComplete:myFunction});</p>
* <p>オブジェクトの属性以外は、下記の特別な値も使えます:</p>
* <table>
* <tr><th>属性</th><th>タイプ</th><th>説明</th></tr>
* <tr><td>delay</td><td>float</td><td>遅延(単位:秒)</td></tr>
* <tr><td>ease</td><td>LEasing (or Function)</td><td>トゥイーンの効果,例えばLEasing.Quad.easeIn や LEasing.Cubic.easeOutなど。ディフォルト値はLEasing.None.easeInです。</td></tr>
* <tr><td>onComplete</td><td>Function</td><td>トゥイーンが終わったら、呼び出す関数</td></tr>
* <tr><td>onStart</td><td>Function</td><td>トゥイーンがスタートする時、呼び出す関数</td></tr>
* <tr><td>onUpdate</td><td>Function</td><td>トゥイーン中、呼び出す関数</td></tr>
* <tr><td>loop</td><td>Boolean</td><td>trueを設定したら、トゥイーンはループします</td></tr>
* </table>
* @return {LTweenLiteChild} LTweenLiteChild instance
* @example
* LInit(1000/50,"legend",800,450,main);
* function main(){
* LGlobal.setDebug(true);
* var circle = new LSprite();
* circle.x = 50;
* circle.y = 50;
* circle.graphics.drawArc("#FF0000",1,[0,0,20,0,Math.PI*2],true,"#FF0000");
* addChild(circle);
* var rect = new LSprite();
* rect.x = 50;
* rect.y = 100;
* rect.graphics.drawRect("#FF00FF",1,[0,0,20,20],true,"#FF00FF");
* addChild(rect);
* LTweenLite.to(circle,2,{x:500,y:400,scaleX:3,scaleY:3,ease:LEasing.Strong.easeInOut})
* .to(circle,2,{x:700,y:50,scaleX:1,scaleY:1,ease:LEasing.Quint.easeIn,onComplete:function(e){
* trace(e.currentTarget);
* trace(e.target);
* }});
* LTweenLite.to(rect,1,{x:500,loop:true,ease:LEasing.Sine.easeInOut})
* .to(rect,1,{x:50,ease:LEasing.Quad.easeInOut});
* }
* @examplelink <p><a href="../../../api/LTweenLite/to.html" target="_blank">実際のサンプルを見る</a></p>
* @public
* @since 1.4.0
*/
to : function ($target, $duration, $vars) {
if (!$target) {
return;
}
var s = this;
var tween = new LTweenLiteChild({}, 0, {});
s.tweens.push(tween);
s.ll_show = s.frame;
tween.to($target, $duration, $vars);
return tween;
},
add : function (tween) {
this.tweens.push(tween);
},
/** @language japanese
* [静的]トゥイーンをストップする。
* @method LTweenLite.remove
* @static
* @param {LTweenLiteChild} tween トゥイーン中のオブジェクト.
* @example
* LInit(1000/50,"legend",800,450,main);
* var tween;
* function main(){
* LGlobal.setDebug(true);
* var rect = new LSprite();
* rect.x = 50;
* rect.y = 50;
* rect.graphics.drawRect("#FF00FF",1,[0,0,20,20],true,"#FF00FF");
* addChild(rect);
* tween = LTweenLite.to(rect,1,{x:500,loop:true,ease:LEasing.Sine.easeInOut})
* .to(rect,1,{x:50,ease:LEasing.Quad.easeInOut});
* var stopButton = new LButtonSample1("stop");
* stopButton.x = 50;
* circle.y = 50;
* stopButton.y = 100;
* addChild(stopButton);
* stopButton.addEventListener(LMouseEvent.MOUSE_UP,stopTween);
* }
* function stopTween(e){
* LTweenLite.remove(tween);
* }
* @examplelink <p><a href="../../../api/LTweenLite/remove.html" target="_blank">実際のサンプルを見る</a></p>
* @public
* @since 1.8.0
*/
remove : function (tween) {
var s = this;
if (typeof tween == UNDEFINED) {
return;
}
for (i = 0, l = s.tweens.length; i < l; i++) {
if (tween.objectIndex == s.tweens[i].objectIndex) {
s.tweens.splice(i, 1);
break;
}
}
},
/** @language japanese
* [静的]全部のトゥイーンをストップする。
* @method LTweenLite.removeAll
* @static
* @example
* LInit(1000/50,"legend",800,450,main);
* var tween;
* function main(){
* LGlobal.setDebug(true);
* var rect = new LSprite();
* rect.x = 50;
* rect.y = 50;
* rect.graphics.drawRect("#FF00FF",1,[0,0,20,20],true,"#FF00FF");
* addChild(rect);
* tween = LTweenLite.to(rect,1,{x:500,loop:true,ease:LEasing.Sine.easeInOut})
* .to(rect,1,{x:50,ease:LEasing.Quad.easeInOut});
* var stopButton = new LButtonSample1("stop");
* stopButton.x = 50;
* circle.y = 50;
* stopButton.y = 100;
* addChild(stopButton);
* stopButton.addEventListener(LMouseEvent.MOUSE_UP,stopTween);
* }
* function stopTween(e){
* LTweenLite.remove(tween);
* }
* @examplelink <p><a href="../../../api/LTweenLite/remove.html" target="_blank">実際のサンプルを見る</a></p>
* @public
* @since 1.8.0
*/
removeAll : function () {
this.tweens.splice(0, this.tweens.length);
}
};
for (var k in p) {
LTweenLite.prototype[k] = p[k];
}
LTweenLiteTimeline = new LTweenLite();
LGlobal.childList.push(LTweenLiteTimeline);
var tween = new LTweenLite();
tween.TYPE_FRAME = LTweenLite.TYPE_FRAME;
tween.TYPE_TIMER = LTweenLite.TYPE_TIMER;
LGlobal.childList.push(tween);
return tween;
})();