Re: [android-developers] check if pressed within circle
On Sep 12, 2012, at 5:09 AM, iQue max.nielse...@gmail.com wrote: this gives a weird result where 90% of the time the stick will set its position to 0,0 when I try to use it. Yup, I made a huge mistake there. Here's revised code; Point imageCenter = new Point(25, 25); Point touchPos = new Point(5, 5); int dx = touchPos.x - imageCenter.x; int dy = touchPos.y - imageCenter.y; float distance = FloatMath.sqrt(dx * dx + dy * dy); final float radius = 25.0f; if (distance radius) { touchPos.x = imageCenter.x + (int)(dx * radius / distance); touchPos.y = imageCenter.y + (int)(dy * radius / distance); } Don't know what I was thinking about earlier... -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] check if pressed within circle
On Sep 12, 2012, at 1:31 PM, iQue max.nielse...@gmail.com wrote: Alright, so I change the previous code to this: int imgCenterX = initx - joystick.get_joystickBg().getWidth()/2 - 50; int imgCenterY = inity - joystick.get_joystickBg().getHeight()/2 - 50; atleast now it dosnt change its pos to 0,0, now it just gets stuck 0,x somewhere, so this code didnt work either. Might help to now that touchinPoint is set through event.getX() and event.getY, but you probably understood that. I've had this problem for over 2 weeks, so if there is anything I can do to make it easier for you to help me please let me know. How are you positioning your joystick image, is it an ImageView or are you drawing it to larger Canvas by yourself? Also from where are you observing MotionEvents? It would help to know to which component (screen or ImageView) MotionEvents and image position are relative to. -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] check if pressed within circle
On Sep 12, 2012, at 1:09 AM, iQue max.nielse...@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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en