Android screen joystick issues

So, I'm trying to create a game using the joystick on the screen, which moves the bitmap around the screen. But when I hold the joystick in any direction and keep it, the bitmap will also stop moving. Its only when I move the joystick makes a raster movement. Basically I want to hold the joystick in the left position, and the raster movement moves to the left until I let go. Everything else in the code works. Any suggestions?

public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) _dragging = true; else if (event.getAction() == MotionEvent.ACTION_UP) _dragging = false; _touchingPoint = new Point(); if (_dragging) { // get the pos int x = (int) event.getX(); int y = (int) event.getY(); _touchingPoint.x = x; _touchingPoint.y = y; double a = _touchingPoint.x - initx; double b = _touchingPoint.y - inity; controllerDistance = Math.sqrt((a * a) + (b * b)); if (controllerDistance > 75) { a = (a / controllerDistance) * 75; b = (b / controllerDistance) * 75; _touchingPoint.x = (int) a + initx; _touchingPoint.y = (int) b + inity; } bitmapPoint.x += a * .05; bitmapPoint.y += b * .05; } else if (!_dragging) { // Snap back to center when the joystick is released _touchingPoint.x = initx; _touchingPoint.y = inity; } } 
+4
source share
2 answers

This was because I only had code to increase the location of the bitmaps in the onTouch method. When the screen is touched but does not move, the event is not logged. The code below should be outside the onTouch method.

 bitmapPoint.x += a * .05; bitmapPoint.y += b * .05; 
+1
source

Try this. This is an open source application for the on-screen joystick for Android.

+2
source

All Articles