-
Notifications
You must be signed in to change notification settings - Fork 9
Using Extensions
Will Blanton edited this page Sep 12, 2019
·
1 revision
The zero.ext
library can be used in two ways:
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!
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!
For more info, please check out the API: http://01010111.com/zerolib/