Tuesday, September 11, 2012

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


changed previous code to this:

            int imgCenterX = (int) ((initx - joystick.get_joystickBg().
getWidth()/2) - 13);
            int imgCenterY = (int) ((inity - joystick.get_joystickBg().getHeight()/2) - 13);
            int dx = imgCenterX - touchingPoint.x;
            int dy = imgCenterY - touchingPoint.y;

            float distance = FloatMath.sqrt(dx * dx + dy * dy);

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

this gives a weird effect where my "stick" which position is controlled by touchingpoint goes to 0,0, 90% of the time. Might help you to know that touchingPoint is a "Point", dont know if points are int or float. Thanks!

Might be important to know that this is how I draw the "stick": canvas.drawBitmap(joystick.get_joystick(),
                                                                                          controls.touchingPoint.x - 13, controls.touchingPoint.y - 13,
                                                                                           null);

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate