Surprisingly this is the only free on screen joystick I was able to find online that wasn't part of some other game engine. It's fairly straight forward and easy to implement.
The movement calculations were a little complex and didn't work for me, so I replaced them with this in the GameControls class:
//get the angle
//double angle = Math.atan2(_touchingPoint.y - inity,_touchingPoint.x - initx)/(Math.PI/180);
float xSpeed = _touchingPoint.x - initx;
float ySpeed = _touchingPoint.y - inity;
xSpeed *= 0.5;
ySpeed *= 0.5;
_pointerPosition.x += xSpeed;
_pointerPosition.y += ySpeed;
// Move the beetle in proportion to how far
// the joystick is dragged from its center
//_pointerPosition.y += Math.sin(angle*(Math.PI/180))*(_touchingPoint.x/70);
//_pointerPosition.x += Math.cos(angle*(Math.PI/180))*(_touchingPoint.x/70);
UPDATE: I am now using this for a dual joystick implementation. See my post on developing with multitouch in Android.
Here's the download and original forum post: http://trostalex.wordpress.com/2010/07/26/on-screen-joystick-source/
No comments:
Post a Comment