开发者

How to move something from a virtual dpad on-screen

开发者 https://www.devze.com 2023-01-03 02:54 出处:网络
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 emulato

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开发者_StackOverflow社区 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


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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消