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.