Skip to content

Commit

Permalink
Fix #29: Shake effect doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteinbeck committed Mar 29, 2017
1 parent b1c6809 commit 408737e
Showing 1 changed file with 18 additions and 27 deletions.
45 changes: 18 additions & 27 deletions src/DisplayObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,14 +535,14 @@ define("WSE.DisplayObject", function (

DisplayObject.prototype.shake = function (command) {

var dx, dy, element, self, xUnit, yUnit, duration, period;
var dx, dy, element, self, xUnit, yUnit, duration, times;
var ox, oy, stage;

self = this;
element = document.getElementById(this.cssid);
dx = command.getAttribute("dx");
dy = command.getAttribute("dy");
period = command.getAttribute("period") || 50;
times = command.getAttribute("times") || 2;
duration = command.getAttribute("duration") || 275;
stage = this.interpreter.stage;

Expand All @@ -560,19 +560,10 @@ define("WSE.DisplayObject", function (
dy = parseInt(dy, 10);
}

function easing (d, t) {

var x = t / period;

while (x > 2.0) {
x -= 2.0;
}

if (x > 1.0) {
x = 2.0 - x;
}

return x;
function easing (distance) {
return function (x) {
return distance * Math.sin(x * (times * 2) * Math.PI);
};
}

if (dx !== null) {
Expand All @@ -587,20 +578,20 @@ define("WSE.DisplayObject", function (
self.interpreter.waitCounter += 1;

transform(
ox - dx,
ox + dx,
0,
1,
function (v) {
element.style.left = v + xUnit;
},
{
duration: duration,
easing: easing
easing: easing(dx)
},
function () {
element.style.left = ox + xUnit;
self.interpreter.waitCounter -= 1;
}
).
then(function () {
element.style.left = ox + xUnit;
self.interpreter.waitCounter -= 1;
});
);
}

if (dy !== null) {
Expand All @@ -615,14 +606,14 @@ define("WSE.DisplayObject", function (
self.interpreter.waitCounter += 1;

transform(
oy - dy,
oy + dy,
0,
1,
function (v) {
element.style.top = v + yUnit;
},
{
duration: duration,
easing: easing
easing: easing(dy)
},
function () {
element.style.top = oy + yUnit;
Expand Down Expand Up @@ -862,4 +853,4 @@ define("WSE.DisplayObject", function (

return DisplayObject;

});
});

0 comments on commit 408737e

Please sign in to comment.