Skip to content
Will Blanton edited this page Sep 13, 2019 · 3 revisions

A Vector2 abstract of Array<Float>!

Usage:

var v1 = Vec2.get(1, 1); // initialize with get()
trace(v1.angle); // 45

var v2:Vec2 = [3, 4]; // you can also initialize using an array!
trace(v2.length); // 5

v1 -= 1; // operations with floats/ints!
trace(v1); // x: 0 | y: 0 | length: 0 | angle: 0

v1 += [0, 5]; // operations with arrays!
trace(v1); // x: 0 | y: 5 | length: 5 | angle: 90
trace(v1.normalize()); // x: 0 | y: 1 | length: 1 | angle: 90
trace(v2.dot(v1)); // 4

v1.angle += 90; // change angle or length inline!
trace(v1); // x: -1 | y: 0 | length: 1 | angle: 180

v1 += v2; // operations with other Vec2s!
trace(v1); // x: 2 | y: 4 | length: 4.47213595499958 | angle: 63.4349488229220242

// Recycle when done!
v1.put();
v2.put();
Clone this wiki locally