I just made one recently, hope this helps.
Note that my velocity calculations are incorrect in processMove(), it uses 
the distance between the touch point and the center of the stick to 
calculate velocity.
This implies that if i touch really far away from the stick, the value is 
scaled dramatically. If you want to fix it, just give it a max value but be 
sure to check if it is negative/positive otherwise the character will not 
be able to move left/up.


//This goes in the onTouchEvent()
switch (event.getAction()) {

case MotionEvent.ACTION_DOWN:
if (stickType == Constants.STICK_MOVABLE) {
// Move knob and base to touch
knobCenterX = touchX;
knobCenterY = touchY;
circleX = touchX;
circleY = touchY;
knobX = knobCenterX;
knobY = knobCenterY;
shouldDrawStick = true;
}
break;

case MotionEvent.ACTION_MOVE:
if (stickType == Constants.STICK_FIXED) {
if (touchX <= circleRadius * 2 && touchY >= canvasHeight - (circleRadius * 
2)) {
processMove();
}
} else if (stickType == Constants.STICK_MOVABLE) {
processMove();
}
break;
case MotionEvent.ACTION_UP:
knobX = knobCenterX;
knobY = knobCenterY;
velX = 0;
velY = 0;
if (stickType == Constants.STICK_MOVABLE)
shouldDrawStick = false;
break;
}
.........
public void processMove()
{
dX = touchX - circleX;
dY = touchY - circleY;
 velX = (float) dX / circleRadius;
velY = (float) dY / circleRadius;
 velX *= 3 * pSpeedMultiplier;
velY *= 3 * pSpeedMultiplier;
 knobX = touchX;
if (knobX < knobCenterX - circleRadius) // Left Bound
knobX = knobCenterX - circleRadius;
else if (knobX > knobCenterX + circleRadius) // Right Bound
knobX = knobCenterX + circleRadius;
 knobY = touchY;
if (knobY < circleY - knobRadius * 2) // Upper Bound
knobY = circleY - knobRadius * 2;
else if (knobY > circleY + knobRadius * 2) // Lower Bound
knobY = circleY + knobRadius * 2;
}

Regards,
Sorab


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

Reply via email to