-2

I got a problem with my touchlistener and actually dont get it work correctly.

    @Override
public boolean onTouchEvent(MotionEvent event) {

    touchControll.processTouchEvent(event); //should do everything!
    invalidate();
    return true; 
}

The Methode processTouchevent simply take the event watch where it was and handles it. So if the touch was inside of the Joypad it handles the joypad "actions". But if i want to handle a hitButton event now it dont react.

Example

    public void processHitButtonTouch(MotionEvent event){
    int touchPosX = (int) event.getX();
    int touchPosY = (int) event.getY();
    if(event.getAction() == MotionEvent.ACTION_DOWN)
        if(touchPosX > Config.BLOCKSIZE*37 && touchPosY > Config.BLOCKSIZE*3 && touchPosY < Config.BLOCKSIZE*7){
            this.hitButton.buttonStatus = Pressed.PRESSED;
        }
    }

on every MotionEvent.ACTION_UP i resett the whole stuff like this:

    if(event.getAction() == MotionEvent.ACTION_UP){
        joyPad.status = Status.IDLE;
        charac.setStatus(Status.IDLE);
        this.hitButton.buttonStatus = Pressed.UNPRESSED;
    }

I tied if it actually handles more than 1 event with the Loggincat and it does (2 touch 2 times downevent logged!). But it simply dont work like i did it here. What have i done wrong?!

Thanks alot for the help!

bemeyer
  • 6,154
  • 4
  • 36
  • 86

1 Answers1

2

The touch events are caught by only one view in Android, so it's normal if your hitButton doesn't react while you keep your finger on the Joypad.

To use multitouch, you have to implement a global view with all your buttons inside (joypad, hitbutton ...). So this view catch the event and pass it on the joypad's touchEventListener or the hitButton's listener.

Edit : Here an exemple with 2 joysticks

http://code.google.com/p/mobile-anarchy-widgets/source/browse/trunk/Widgets/src/com/MobileAnarchy/Android/Widgets/Joystick/DualJoystickView.java?r=30

Edit2 : a good tutorial

http://android-developers.blogspot.fr/2010/06/making-sense-of-multitouch.html

Goo
  • 1,318
  • 1
  • 13
  • 31
  • Dont i do this already? I got my surfaceview where i Render my Game and the Buttons and pass all touchevents to the Touchcontroller. – bemeyer Nov 20 '12 at 13:26
  • Isnt the surfaceview like you said the global View? There are just those touches to Handle. I just dont get it i am sorry for that. Does every of the buttons need his own View to handle the touches? – bemeyer Nov 20 '12 at 13:32
  • 2
    Not exactly, if i remember ACTION_UP/DOWN are for the first finger. To catch actions on extra finger, you should use pointer and ACTION_POINTER_UP & co. http://stackoverflow.com/a/4269592/1720391 – Goo Nov 20 '12 at 13:38
  • So if i use ACTION_POINTER_UP/DOWN it schould work without anything else if i got that right. – bemeyer Nov 20 '12 at 13:40
  • Thanks for that Help i hope ill get it with that tutorial. – bemeyer Nov 20 '12 at 13:50