cocos2dx3.2 on Android Return key does not respond to problem resolution

Source: Internet
Author: User

The reason is simple, the Android key event is triggered by the onkeyreleased. Rather than onkeypressed.

The following key code is affixed

1.android part of the response button, then the JNI interface is called

    public boolean onKeyDown (final int pkeycode, final keyevent pkeyevent) {     & nbsp  switch (pkeycode) {            case keyevent.keycode_back:                  Cocos2dxVideoHelper.mVideoHandler.sendEmptyMessage (cocos2dxvideohelper.keyeventback);             case keyevent.keycode_menu:             Case keyevent.keycode_dpad_left:            case keyevent.keycode_dpad _right:            case keyevent.keycode_dpad_up:             case keyevent.keycode_dpad_down:             case keyevent.keycode_enter:            case Keyevent.keycode_media_play_pause:            case keyevent.keycode_dpad_center:                 this.queueevent (New Runnable () {                     @Override                      public void Run () {                        <span style= "color:# FF0000; " > cocos2dxglsurfaceview.this.mcocos2dxrenderer.handlekeydown (Pkeycode);</span>                     }                 });                return true;            default:                return super.onkeydown (Pkeycode, pkeyevent);         }    }
2.jni interface is called, key event creation (TOUCHESJNI.CPP)

    Jniexport Jboolean jnicall Java_org_cocos2dx_lib_cocos2dxrenderer_nativekeydown (JNIENV * env, jobject thiz, Jint KeyCode) {        director* pdirector = Director::getinstance ();                Auto Iterkeycode = G_keycodemap.find (keycode);        if (Iterkeycode = = G_keycodemap.end ()) {            return jni_false;        }                Cocos2d::eventkeyboard::keycode Cocos2dkey = g_keycodemap.at (keycode);        <span style= "color: #FF0000;" >cocos2d::eventkeyboard event (Cocos2dkey, false); Although it is KeyDown, it is set to Released message </span>        cocos2d::D irector::getinstance ()->geteventdispatcher () Dispatchevent (&event);        return jni_true;}            }

3. The next step is needless to say. So under Android. The key event will never respond to onkeypressed messages.

Ah .....



cocos2dx3.2 on Android Return key does not respond to problem resolution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.