tags:

views:

90

answers:

1

Hello everyone,

I've started a little game, and so far I'm moving a little guy with onKeyDown() and the DPAD from Android Emulator. Now what I want to do is to add 4 buttons on the screen (like in a GAMEBOY emulator for example) and these buttons should move my little guy. With a clickListener and onClick() (or touchListener and onTouch()), it's ok for one move but how to do if I want that my little guy continues moving when I stay clicked on the button ??? Buttons are enough or should I make a 4 arrows soft keyboard or anything else ??

Thanks

A: 

So with some searchs, I've now a virtual joystick on screen using :

public boolean onTouchEvent(MotionEvent event) {
    float positionX = event.getX();
    float positionY = event.getY();

        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
        // Screen is pressed for the first time
        break;
        case MotionEvent.ACTION_MOVE:
        // Screen is still pressed, float have been updated
        break;
        case MotionEvent.ACTION_UP:
        // Screen is not anymore touched
        break;
        }
        return true;
    }
    return super.onTouchEvent(event);
}
Kriegalex