1
+ /**
2
+ * Created by wander on 14-12-22.
3
+ */
4
+ module egret . action {
5
+
6
+ export class MoveBy extends ActionInterval {
7
+
8
+
9
+ private _positionDelta :cc . Point ;
10
+ private _startPosition :cc . Point ;
11
+ private _previousPosition :cc . Point ;
12
+
13
+
14
+ constructor ( ) {
15
+
16
+ super ( ) ;
17
+
18
+ this . _positionDelta = cc . p ( 0 , 0 ) ;
19
+ this . _startPosition = cc . p ( 0 , 0 ) ;
20
+ this . _previousPosition = cc . p ( 0 , 0 ) ;
21
+ }
22
+
23
+ public initWithDuration ( duration :number , position ) {
24
+ super . initWithDuration ( duration , position ) ;
25
+ this . _positionDelta . x = position . x ;
26
+ this . _positionDelta . y = position . y ;
27
+
28
+
29
+ }
30
+
31
+ /**
32
+ * @param {Number } target
33
+ */
34
+ public startWithTarget ( target :DisplayObject ) {
35
+ super . startWithTarget ( target ) ;
36
+ var locPosX = target . x ;
37
+ var locPosY = target . y ;
38
+ this . _previousPosition . x = locPosX ;
39
+ this . _previousPosition . y = locPosY ;
40
+ this . _startPosition . x = locPosX ;
41
+ this . _startPosition . y = locPosY ;
42
+ }
43
+
44
+
45
+ /**
46
+ * @param {Number } time time in seconds
47
+ */
48
+ public update ( time ) {
49
+ if ( this . target ) {
50
+ var x = this . _positionDelta . x * time ;
51
+ var y = this . _positionDelta . y * time ;
52
+ var locStartPosition = this . _startPosition ;
53
+ if ( false ) { //cc.ENABLE_STACKABLE_ACTIONS) { todo
54
+ // var targetX = this._target.getPositionX();
55
+ // var targetY = this._target.getPositionY();
56
+ // var locPreviousPosition = this._previousPosition;
57
+ //
58
+ // locStartPosition.x = locStartPosition.x + targetX - locPreviousPosition.x;
59
+ // locStartPosition.y = locStartPosition.y + targetY - locPreviousPosition.y;
60
+ // x = x + locStartPosition.x;
61
+ // y = y + locStartPosition.y;
62
+ //
63
+ // this._target.setPosition(x, y);
64
+ // locPreviousPosition.x = x;
65
+ // locPreviousPosition.y = y;
66
+ } else {
67
+ this . target . x = locStartPosition . x + x ;
68
+ this . target . y = locStartPosition . y + y ;
69
+ }
70
+ }
71
+ }
72
+
73
+
74
+ public static create ( duration , deltaPosition ) {
75
+ var moveBy = new MoveBy ( ) ;
76
+ moveBy . initWithDuration ( duration , deltaPosition ) ;
77
+ return moveBy ;
78
+ }
79
+ }
80
+
81
+
82
+ }
83
+
84
+ module cc {
85
+
86
+ export function p ( x :number , y :number ) :Point {
87
+ return { x : x , y : y } ;
88
+ }
89
+
90
+ export interface Point {
91
+
92
+ x :number ;
93
+
94
+ y :number ;
95
+ }
96
+
97
+ }
0 commit comments