mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-07-19 18:32:04 -04:00
Change BouncingBalls example to use event.delta for throwing balls.
This commit is contained in:
parent
0dfa2b7413
commit
44aa9254ea
1 changed files with 6 additions and 9 deletions
|
@ -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);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue