phaser/Phaser/system/easing/Elastic.js

69 lines
2.2 KiB
JavaScript
Raw Normal View History

2013-08-11 23:52:35 +00:00
var Phaser;
(function (Phaser) {
/// <reference path="../../Game.ts" />
/**
* Phaser - Easing - Elastic
*
* For use with Phaser.Tween
*/
(function (Easing) {
var Elastic = (function () {
function Elastic() { }
Elastic.In = function In(k) {
var s, a = 0.1, p = 0.4;
if(k === 0) {
return 0;
}
if(k === 1) {
return 1;
}
if(!a || a < 1) {
a = 1;
s = p / 4;
} else {
s = p * Math.asin(1 / a) / (2 * Math.PI);
}
return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
};
Elastic.Out = function Out(k) {
var s, a = 0.1, p = 0.4;
if(k === 0) {
return 0;
}
if(k === 1) {
return 1;
}
if(!a || a < 1) {
a = 1;
s = p / 4;
} else {
s = p * Math.asin(1 / a) / (2 * Math.PI);
}
return (a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
};
Elastic.InOut = function InOut(k) {
var s, a = 0.1, p = 0.4;
if(k === 0) {
return 0;
}
if(k === 1) {
return 1;
}
if(!a || a < 1) {
a = 1;
s = p / 4;
} else {
s = p * Math.asin(1 / a) / (2 * Math.PI);
}
if((k *= 2) < 1) {
return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
}
return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
};
return Elastic;
})();
Easing.Elastic = Elastic;
})(Phaser.Easing || (Phaser.Easing = {}));
var Easing = Phaser.Easing;
})(Phaser || (Phaser = {}));