Skip to content
Will Blanton edited this page Sep 12, 2019 · 1 revision

Usage - Part 1 - The Basics:

The zero.ext library can be used in two ways:

1) A collection of helpful functions

Step One: import

import zero.extensions.FloatExt;

Step Two: use the functions!

value = 12;
value = FloatExt.clamp(value, 0, 10);
// value is now equal to 10!

2) A collection of extensions!

Haxe has a cool feature called Extensions. Learn more by clicking on that link, but in short, we can use the functions in these classes as if they were functions build in to the types we're working on!

Step One: import? NO! We'll be USING these classes!

using zero.extensions.FloatExt;

Step Two: use the functions!

value = 12;
value = value.clamp(0, 10);
// value is now equal to 10!

See the difference? I personally think it looks way cleaner and it's also way easier to chain multiple functions:

First method:

// Getting a relative degree (0 - 360) from a given radian:
var radian = Math.PI;
var degree = FloatExt.get_relative_degree(FloatExt.rad_to_deg(radian));
// degree = 180

Second method:

// Getting a relative degree (0 - 360) from a given radian:
var radian = Math.PI;
var degree = radian.rad_to_deg().get_relative_degree();
// degree = 180

I think that looks way better!

Clone this wiki locally