-
Notifications
You must be signed in to change notification settings - Fork 277
/
Copy pathmultimove.js
83 lines (78 loc) · 2.65 KB
/
multimove.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
goog.provide('rb.MultiMove');
goog.require('lime.animation.MoveBy');
/**
* Object for moving lot of elements together.
* Done as a specific test. No real effect unless very big board (and first animation)
*/
rb.MultiMove = function() {
this.requests_ = {};
this.numReq_ = 0;
};
/**
* Add target node with its delta
* @param {lime.Node} node Node to move.
* @param {goog.math.Vec2} delta Offset to move.
*/
rb.MultiMove.prototype.addNode = function(node,delta) {
var key = delta.x + '_' + delta.y;
if (!goog.isDef(this.requests_[key])) {
this.requests_[key] = [];
}
this.requests_[key].push([node, delta]);
this.numReq_++;
};
/**
* Return number of actions
* @return {number} NUmber of actions.
*/
rb.MultiMove.prototype.getNumActions = function() {
return this.numReq_;
};
/**
* Play the animation
*/
rb.MultiMove.prototype.play = function(opt_static) {
var action, longest_action, longest_duration = 0;
for (var i in this.requests_) {
var req = this.requests_[i];
action = new lime.animation.MoveBy(req[0][1]).setSpeed(.3);
if (longest_duration < action.getDuration()) {
longest_action = action;
longest_duration = action.getDuration();
}
if (!opt_static && req.length > 15) {
var layer = new lime.Layer().setRenderer(lime.Renderer.CANVAS);
var oldparent = req[0][0].getParent();
var grandparent = oldparent.getParent();
for (var j = 0; j < req.length; j++) {
var node = req[j][0];
node.getParent().removeChild(node);
layer.appendChild(req[j][0]);
}
grandparent.appendChild(layer);
goog.events.listen(action, lime.animation.Event.STOP, function() {
var parent = this.getParent();
parent.removeChild(this);
var pos = this.getPosition();
var i = this.children_.length - 1;
while (i >= 0) {
var n = this.children_[i];
this.removeChild(n);
n.setRenderer(lime.Renderer.DOM);
grandparent.layers[n.c].appendChild(n);
var pp = (goog.math.Coordinate.sum(pos, n.getPosition()));
n.setPosition(goog.math.Coordinate.sum(pos, n.getPosition()));
i--;
}
},false, layer);
layer.runAction(action);
}
else {
for (var j = 0; j < req.length; j++) {
action.addTarget(req[j][0]);
}
action.play();
}
}
return longest_action;
};