Open glennmichaelmejias opened 4 years ago
Right now you get angle and distance from the center. You need to do some math to reverse it back to x,y. Or some PR is welcome that would allow to choose a mode (to return either that or coordinates)
I don't know if you're still interested in the solution or if you figured it out yourself, but the math to get x
and y
is as follows (r
is the radius and a
the angle):
x = r * cos(a)
y = r * sin(a)
To add to @chrismit3s 's answer, you would first need to convert the angle given by the JoystickView widget into radians, as the cos(x) and sin(x) functions from the dart:math library only accept angles in radians.
Here would be the code to implement this:
import 'dart:math';
import 'package:control_pad/views/circle_view.dart';
...
JoystickView(
onDirectionChanged: (double degrees, double distanceFromCenter) {
double radians = degrees * pi / 180;
double x = cos(radians) * distanceFromCenter;
double y = sin(radians) * distanceFromCenter;
}
)
How to get the x and y of the joystick? there are only two results on directionchanged.