So, I'm trying to a drawable move based on how you move your finger
after touching the screen. I'm getting very weird results, with the
drawable moving horizontally being very precise (low sensitivity) and
when moving up or down having incredibly inaccurate movement (I cannot
make the drawable move straight up or down, it won't go less than a 45
degree angle, making it have to zigzag to get it to move down or up).
Here is the code I'm using:
TouchX = V.TX; // The fingers X location
TouchY = V.TY; // The fingers Y location
xDif = TouchX - V.CenterX; //The difference between the finger
location and the control location
yDif = TouchY - V.CenterY; //The difference between the finger
location and the control location
DragDist = (float) Math.sqrt((xDif*xDif)+(yDif*yDif)); //Check how far
the finger is away from the control center
if(DragDist > 15 && DragDist < 75){
Slope = (TouchY - V.CenterY) / (TouchX - V.CenterX); // Detect
the
slope of the difference
DegreeSlopeY = Math.atan(Slope); //Change the slope into usable
degrees
DegreeSlopeY = Math.abs(DegreeSlopeY); // Get the absolute value
DegreeSlopeX = 90 - DegreeSlopeY; //Aids in calculating the X
and Y
values later
NewY = (MoveSpeed * Math.sin(DegreeSlopeY)); //MoveSpeed is the
amount it should move along the slope
NewX = (MoveSpeed * Math.sin(DegreeSlopeX));
if(TouchX < V.CenterX) NewX = -NewX; //Makes it able to move in
all
directions
if(TouchY < V.CenterY) NewY = -NewY; //Makes it able to move
in all
directions
}
Does anyone know what I'm doing wrong? All my variables are double, as
I heard that was a more accurate variable. Does this have something to
do with the screen size or aspect ratio? If so how would I account for
that? Any help would be greatly appreciated :)
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en