Support for the tvOS micro gamepad as a CCController (#17517)

* Fixes cocos2d build for tvOS.

* Support for the tvOS micro gamepad as a CCController.
This commit is contained in:
pyrosphere 2017-03-16 02:33:36 +00:00 committed by minggo
parent f0061c3ddc
commit e3bff6452d
1 changed files with 33 additions and 1 deletions

View File

@ -254,7 +254,7 @@ void Controller::registerListeners()
}
};
}
else
else if (_impl->_gcController.gamepad != nil)
{
_impl->_gcController.gamepad.dpad.up.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
onButtonEvent(Key::BUTTON_DPAD_UP, pressed, value, button.isAnalog);
@ -300,6 +300,38 @@ void Controller::registerListeners()
}
};
}
#if defined(CC_TARGET_OS_TVOS)
else if (_impl->_gcController.microGamepad != nil)
{
_impl->_gcController.microGamepad.dpad.up.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
onButtonEvent(Key::BUTTON_DPAD_UP, pressed, value, button.isAnalog);
};
_impl->_gcController.microGamepad.dpad.down.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
onButtonEvent(Key::BUTTON_DPAD_DOWN, pressed, value, button.isAnalog);
};
_impl->_gcController.microGamepad.dpad.left.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
onButtonEvent(Key::BUTTON_DPAD_LEFT, pressed, value, button.isAnalog);
};
_impl->_gcController.microGamepad.dpad.right.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
onButtonEvent(Key::BUTTON_DPAD_RIGHT, pressed, value, button.isAnalog);
};
_impl->_gcController.microGamepad.valueChangedHandler = ^(GCMicroGamepad *gamepad, GCControllerElement *element){
if (element == gamepad.buttonA)
{
onButtonEvent(Key::BUTTON_A, gamepad.buttonA.isPressed, gamepad.buttonA.value, gamepad.buttonA.isAnalog);
}
else if (element == gamepad.buttonX)
{
onButtonEvent(Key::BUTTON_X, gamepad.buttonX.isPressed, gamepad.buttonX.value, gamepad.buttonX.isAnalog);
}
};
}
#endif
_impl->_gcController.controllerPausedHandler = ^(GCController* gcCon){