Solve the Cocos2d-x into the game, adjust the sound key is not used, you need to press the back key, the sound key is available Bug, cocos2d-xbug

Source: Internet
Author: User

Solve the Cocos2d-x into the game, adjust the sound key is not used, you need to press the back key, the sound key is available Bug, cocos2d-xbug

We know that all button events are processed in view,

The main interface of our game inherits Cocos2dxGLSurfaceView, so there should be a problem with the button processing in this file, so we found this file,

This is obviously the source file of 2d-x, But we add a button to handle the event with a try.

After the result is added, there is no effect. It is the same as not added, so we know it is not the problem here.

So let's think again, based on the error prompts.



We don't know why, but when we enter the game and click the volume adjustment key, this line of code will appear. from the top down, we can see that it is not EditText or Cocos2dxGLSurfaceView, after Cocos2dxGLSurfaceView event processing is modified, there is no effect, that is, the EditText event processing function is modified in Cocos2dxEditText. add the following code to java:

@ Override
Public boolean onKeyDown (final int pKeyCode, final KeyEvent pKeyEvent ){
Super. onKeyDown (pKeyCode, pKeyEvent );
Int currentVolume = audio. getStreamVolume (AudioManager. STREAM_MUSIC );
/* Let GlSurfaceView get focus if back key is input .*/
If (pKeyCode = KeyEvent. KEYCODE_BACK ){
This. mCocos2dxGLSurfaceView. requestFocus (); // 1
}
Else if (pKeyCode = KeyEvent. KEYCODE_VOLUME_DOWN)
{
Audio. setStreamVolume (AudioManager. STREAM_MUSIC, currentVolume-1, 1); // 2
}
Else if (pKeyCode = KeyEvent. KEYCODE_VOLUME_UP)
{
Audio. setStreamVolume (AudioManager. STREAM_MUSIC, currentVolume + 1, 1); // 3
}
Return true;
}


Re-compile the apk to adjust the volume key.

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.