Tuesday, September 11, 2012

[android-developers] check if pressed within circle

I'm using joysticks to controls my game-characters movement and the direction he fires, and to keep these joysticks within its bound I use this code:

            if (touchingPoint.x < (int) (steeringxMesh - 25)) {
                touchingPoint.x = (int) (steeringxMesh - 25);
            }
            if (touchingPoint.x > (int) (steeringxMesh + 25)) {
                touchingPoint.x = (int) (steeringxMesh + 25);
            }
            if (touchingPoint.y < (int) (yMesh - 25)) {
                touchingPoint.y = (int) (yMesh - 25);
            }
            if (touchingPoint.y > (int) (yMesh + 25)) {
                touchingPoint.y = (int) (yMesh + 25);
            }

this code makes my streering a big pain in the ass, since it basicly makes my joystick move within a square.

I want to change this so it checks if Ive pressed within a circle the size of my joysticks background-image.

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.

--
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