fix display errors of edge bouncing

pull/29/head
Michael Aschauer 2017-05-30 17:48:26 +02:00
rodzic 77a08a6da7
commit 15df9454d2
1 zmienionych plików z 30 dodań i 0 usunięć

Wyświetl plik

@ -1437,3 +1437,33 @@ SpriteMorph.prototype.blockTemplates = function (category) {
}
return blocks;
};
SpriteMorph.prototype.bounceOffEdge = function () {
// taking nested parts into account
var stage = this.parentThatIsA(StageMorph),
fb = this.nestingBounds(),
dirX,
dirY;
if (!stage) {return null; }
if (stage.bounds.containsRectangle(fb)) {return null; }
dirX = Math.cos(radians(this.heading - 90));
dirY = -(Math.sin(radians(this.heading - 90)));
if (fb.left() < stage.left()) {
dirX = Math.abs(dirX);
}
if (fb.right() > stage.right()) {
dirX = -(Math.abs(dirX));
}
if (fb.top() < stage.top()) {
dirY = -(Math.abs(dirY));
}
if (fb.bottom() > stage.bottom()) {
dirY = Math.abs(dirY);
}
this.setHeading(degrees(Math.atan2(-dirY, dirX)) + 90);
};