-
Notifications
You must be signed in to change notification settings - Fork 21
/
MatrixSample.hx
50 lines (41 loc) · 1.29 KB
/
MatrixSample.hx
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
import sample.Sprite;
import sample.Square;
import tweenxcore.structure.FloatChange;
import tweenxcore.structure.FloatChangePart;
using tweenxcore.Tools;
#if flash
import flash.geom.Matrix in MatrixImpl;
#else
private class MatrixImpl {
public var a:Float = 1;
public var b:Float = 0;
public var c:Float = 0;
public var d:Float = 1;
public var tx:Float = 0;
public var ty:Float = 0;
public function new() {}
}
#end
class MatrixSample extends Sprite {
public static var TOTAL_FRAME:Int = 40;
private var square:Square;
private var frameCount:Int = 0;
private var matrix:MatrixImpl;
public function new() {
super();
addChild(square = new Square());
square.y = Square.SIZE * 2;
matrix = new MatrixImpl();
matrix.createSimilarityTransform(100, 0, 350, 120);
}
public function update():Void {
var floatChange = new FloatChange(frameCount, frameCount += 1);
floatChange.handlePart(0.0, 40.0, updatePart);
}
private function updatePart(part:FloatChangePart):Void {
var x = part.current;
var y = part.current.sinByRate().lerp(0, 0.1);
square.x = matrix.a * x + matrix.c * y + matrix.tx;
square.y = matrix.b * x + matrix.d * y + matrix.ty;
}
}