Change BouncingBalls example to use event.delta for throwing balls.

This commit is contained in:
Jonathan Puckey 2011-02-21 15:32:59 +01:00
parent 0dfa2b7413
commit 44aa9254ea

View file

@ -52,10 +52,10 @@
var Ball = Base.extend({ var Ball = Base.extend({
initialize: function(point, vector) { initialize: function(point, vector) {
if (vector.isZero()) { if (!vector || vector.isZero()) {
this.vector = Point.random().multiply(5); this.vector = Point.random().multiply(5);
} else { } else {
this.vector = vector; this.vector = vector.multiply(1.5);
} }
this.point = point; this.point = point;
this.dampen = 0.4; this.dampen = 0.4;
@ -102,18 +102,15 @@
balls.push(ball); balls.push(ball);
} }
var lastPoint; var lastDelta;
tool = new Tool({ tool = new Tool({
onMouseDown: function(event) {
lastPoint = event.point;
},
onMouseDrag: function(event) { onMouseDrag: function(event) {
lastPoint = event.point; lastDelta = event.delta;
}, },
onMouseUp: function(event) { onMouseUp: function(event) {
var delta = lastPoint.subtract(event.point); var ball = new Ball(event.point, lastDelta);
var ball = new Ball(event.point, delta);
balls.push(ball); balls.push(ball);
lastDelta = null;
} }
}); });
setInterval(draw, 30); setInterval(draw, 30);