add static method for lerp on a Vector #5903
hendrikras
started this conversation in
Feature Requests
Replies: 2 comments
-
I can grab this one. Does setting up a static method on the Vector2 class sound okay? Something like:
|
Beta Was this translation helpful? Give feedback.
0 replies
-
@photonstorm @hendrikras pull request at #5858! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
**When performing the lerp function on a Vector2 instance the result of that operation wil be used to overwrite the original value of that Vector2's instance.
Meaning the lerp function is not immutable. And after reading the documentation it is not supposed to be.
So that is why I am not posting this as a bug.
Here is the thing though; I usually do not want to lose the original Vector2's value. So have to remember to clone the original Vector2 every time a interpolation is needed. That tends to create hard to find bugs. Or at least decrease readability of the code.
The Geom classes have static methods for things like GetPoint, even though you can also do .getPoint operations on an instance object. And as far as I know the latter does not really mutate the instance member vars.
Could not find such a static method for interpolation, well there is Phaser.Math.Linear but that does not return a new Vector2, or even Point;
So why not include a static method for interpolation that takes 2 Vector2 in a similar fashion as GetPoint does for geom classes and returns a brand new Vector2 as the result?
I include here a demo to show what i mean:
https://codepen.io/hendrikras/pen/abvePYd?editors=0011
Beta Was this translation helpful? Give feedback.
All reactions