游戏中用脚开飞机实现方案

看看这个图片,有人用脚开飞机,用几个踏板去控制,在游戏中,开飞机的操作比较简单,上升,下降,加减油门,方向左,方向右。

 android设备中,使用模拟点击就可以实现这个功能,在操作踏板的时候发送对应的touch事件,具体可以参考frameworks/base/cmds/input/src/com/android/commands/input/Input.java

209    private void sendTap(int inputSource, float x, float y) {
210        long now = SystemClock.uptimeMillis();
211        injectMotionEvent(inputSource, MotionEvent.ACTION_DOWN, now, x, y, 1.0f);
212        injectMotionEvent(inputSource, MotionEvent.ACTION_UP, now, x, y, 0.0f);
213    }


298    private void injectMotionEvent(int inputSource, int action, long when, float x, float y, float pressure) {
299        final float DEFAULT_SIZE = 1.0f;
300        final int DEFAULT_META_STATE = 0;
301        final float DEFAULT_PRECISION_X = 1.0f;
302        final float DEFAULT_PRECISION_Y = 1.0f;
303        final int DEFAULT_EDGE_FLAGS = 0;
304        MotionEvent event = MotionEvent.obtain(when, when, action, x, y, pressure, DEFAULT_SIZE,
305                DEFAULT_META_STATE, DEFAULT_PRECISION_X, DEFAULT_PRECISION_Y,
306                getInputDeviceId(inputSource), DEFAULT_EDGE_FLAGS);
307        event.setSource(inputSource);
308        Log.i(TAG, "injectMotionEvent: " + event);
309        InputManager.getInstance().injectInputEvent(event,
310                InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
311    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值