Tuesday, September 11, 2012

Re: [android-developers] check if pressed within circle

On Sep 12, 2012, at 1:09 AM, iQue <max.nielsen90@gmail.com> wrote:
>
> Say the joysticks background image is 50x50, how do I make a circle in android with this size in mind, and how do i check if im pressing within it.

Use distance,

int dx = imgCenterX - touch.x;
int dy = imgCenterY - touch.y;
float distance = FloatMath.sqrt(dx * dx + dy * dy);

// Out of bounds check.
if (distance > 25) {
touch.x *= 1f / distance;
touch.y *= 1f / distance;
}

Or something like this might work.

--
H

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment