-
Now that I have my game out on the original platforms I support, I took the opportunity to build the Apple TV variant - to be honest I didn't expect it to work. However built nicely, ran, and went through the startup sequences. Then came to the first bit of user input and was expected nothing worked. Everything I have done so far is mouse, touch, or key selection. I have not Gamepad / Remote support at all. I managed to use the Remote with the very rudimentary touch support, so I managed to navigate part of my menu and in to the game - and just amazing that it works! The thing is - I have no idea what I am meant to be adding. I tried trust google, but could find anything interesting for Apple TV support for Cocos2d-x or Axmol. I have some buttons inside Layout. I have some widget stuff. I have some Menu and MenuItem elements. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 15 replies
-
That is strange, because the controller should be supported. The code is in |
Beta Was this translation helpful? Give feedback.
-
Hi, 1 - My scene inherit from ax::Scene, normally: class MenuScene : public ax::Scene {
private:
void onControllerKeyDown(ax::Controller *controller, int keyCode, ax::Event *event);
} 2 - On init method you need: bool MenuScene::init() {
// super init first
if (!Scene::init()) {
return false;
}
// controller
#if (AX_TARGET_PLATFORM != AX_PLATFORM_WASM)
Controller::startDiscoveryController();
#endif
auto listener = EventListenerController::create();
listener->onKeyDown = AX_CALLBACK_3(MenuScene::onControllerKeyDown, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
// schedule update
scheduleUpdate();
return true;
}
void MenuScene::onControllerKeyDown(Controller *controller, int keyCode, Event *event) {
if (window) {
window->onControllerKeyDown(controller, keyCode, event);
}
} In my case i have a class for each FairyGUI window, but you dont need. 3 - After receive the event from controller, you make your logic: void MenuWindowGUI::onControllerKeyDown(Controller *controller, int keyCode, Event *event) {
switch (keyCode) {
case Controller::BUTTON_DPAD_UP:
case Controller::BUTTON_DPAD_LEFT:
selectPreviousControl();
break;
case Controller::BUTTON_DPAD_DOWN:
case Controller::BUTTON_DPAD_RIGHT:
selectNextControl();
break;
case Controller::BUTTON_A:
if (controlListIndex < 0) {
return;
}
auto selectedButton = getContentPane()->getChildByPath(controlList[controlListIndex]);
if (selectedButton) {
selectedButton->dispatchEvent(UIEventType::Click);
}
break;
}
} 4 - In your <key>GCSupportsControllerUserInteraction</key>
<true/>
<key>GCSupportedGameControllers</key>
<array>
<dict>
<key>ProfileName</key>
<string>ExtendedGamepad</string>
</dict>
</array> |
Beta Was this translation helpful? Give feedback.
-
So to conclude this discussion, here are my findings for Apple TV Remote and Controllers.
|
Beta Was this translation helpful? Give feedback.
So to conclude this discussion, here are my findings for Apple TV Remote and Controllers.