AppleTV support

I created a new topic for my AppleTV support branch, so that it is clear that you are asking questions about my branch and not others.

URL for the branch: https://github.com/elvman/cocos2d-x/tree/tvos

What is done:

  1. Ported cocos2d-x (including CocosDenshion) to tvOS;
  2. Implemented GCMicroGamepad (also implemented allowsRotation and reportsAbsoluteDpadValues flags);
  3. Compiled all the needed 3rd party libs for tvOS (https://github.com/elvman/cocos2d-x-3rd-party-libs-bin);
  4. Disabled touch events.

What has to be done

  1. Port all samples to tvOS and allow them to be controlled by Apple remote.

To try out the AppleTV port, you can use my sample: https://github.com/elvman/tvos-test

I will post regular updates here. You are welcome post your suggestions, games and experience with Apple AppStore here.

3 Likes

Great work done! Would be interesting to see little FAQ how you got compiled third party libs for Apple TV.

@energyy You can see the source code here: https://github.com/elvman/cocos2d-x-3rd-party-libs-src

Removed touch events from tvOS target, because they messed up cocos2d-x GUI. Please use Controllers onKeyDown and onKeyRepeat event listeners instead.

Added navigation example with menu button in my tvOS sample (https://github.com/elvman/tvos-test). If you are in the game menu, you will get back to main menu with menu button, otherwise the app is closed.

How can I compile sample? There’s tv os library missing…

edit: Found link link, too bad :smiley:

edit2: brew is working, I’ve installed all depedencies, but still:

error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: no input files specified
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo [input_file] … [-arch <arch_type> input_file] … [-info] [-detailed_info] [-output output_file] [-create] [-arch_blank <arch_type>] [-thin <arch_type>] [-remove <arch_type>] … [-extract <arch_type>] … [-extract_family <arch_type>] … [-verify_arch <arch_type> …] [-replace <arch_type> <file_name>] …
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can’t open input file: tvos/rapidjson/prebuilt/librapidjson.a (No such file or directory)

I’m running following command:

./build.sh -p=tvos --libs=all --arch=all --mode=release

  1. Download the sample from https://github.com/elvman/tvos-test
  2. Download the cocos2d-x tvOS branch: https://github.com/elvman/cocos2d-x/tree/tvos
  3. Download my cocos2d-x build script and put it in the cocos2d-x build directory: https://github.com/elvman/cocos2d-x-build-script
  4. Run “./build.sh -p appletv” to build tvOS libs
  5. Got to tvOS sample xcode settings and change the COCOS2DX_HOME to the location where you have cocos2d-x downloaded:
    http://i.imgur.com/zIVAvd3.png

Anyone has Undefined symbols for architecture x86_64: errors in sample project?

Why are you building for x86_64 architecture? AppleTV has arm64.

I don’t. I have valid architectures arm64 only. I don’t know why it yells about x86_64.

Are you building for AppleTV simulator?

Yeah.

Of course you are building for simulator. Did you build cocos2d for AppleTV simulator? You should run “./build.sh -h” to see all available platforms.

That was it. Thanks again. I forgot simulator has different architecture. Just one more question: now I have 4 directories: Debug-appletvos, Debug-appletvsimulator, Release-appletvos, Release-appletvsimulator. If I want to use simulator I have to add (drag&drop) reference to .a file from Debug-appletvsimulator, so when I want to switch for device (or just release) I have to remove older link and add the new one. Isn’t there easier method? I don’t have to do it while using cocos2d-x for ios or mac. Also why is debug library so huge (over 600mb) while release is small (little over 30mb)?

I don’t have usb-c cable to my apple tv so I have to stick to simulator. In logs I can see:

Controller connected ExtendedGamepad

And when I’m trying some stuff on Apple TV Remove I’m not getting any callbacks…

edit:
Also, did you try using cocos studio scene? I’ve added necessary imports in MainMenu.h:

#include “cocostudio/CocoStudio.h”
#include “ui/CocosGUI.h”

and I’m getting following error:

Undefined symbols for architecture x86_64:
“cocostudio::Light3DReader::createInstance()”, referenced from:
cocos2d::CSLoader::CSLoader() in libcocos2d tvOS.a(CSLoader.o)
“cocos2d::StencilStateManager::onAfterVisit()”, referenced from:
cocos2d::ui::Layout::stencilClippingVisit(cocos2d::Renderer*, cocos2d::Mat4 const&, unsigned int) in libcocos2d tvOS.a(UILayout.o)
“cocos2d::StencilStateManager::onBeforeVisit()”, referenced from:
cocos2d::ui::Layout::stencilClippingVisit(cocos2d::Renderer*, cocos2d::Mat4 const&, unsigned int) in libcocos2d tvOS.a(UILayout.o)
“cocos2d::StencilStateManager::onAfterDrawStencil()”, referenced from:
cocos2d::ui::Layout::stencilClippingVisit(cocos2d::Renderer*, cocos2d::Mat4 const&, unsigned int) in libcocos2d tvOS.a(UILayout.o)
“cocos2d::StencilStateManager::StencilStateManager()”, referenced from:
cocos2d::ui::Layout::Layout() in libcocos2d tvOS.a(UILayout.o)
“cocos2d::ui::PageViewIndicator::setDirection(cocos2d::ui::ScrollView::Direction)”, referenced from:
cocos2d::ui::PageView::setDirection(cocos2d::ui::ScrollView::Direction) in libcocos2d tvOS.a(UIPageView.o)
cocos2d::ui::PageView::setIndicatorEnabled(bool) in libcocos2d tvOS.a(UIPageView.o)
“cocos2d::ui::PageViewIndicator::setSpaceBetweenIndexNodes(float)”, referenced from:
cocos2d::ui::PageView::setIndicatorSpaceBetweenIndexNodes(float) in libcocos2d tvOS.a(UIPageView.o)
“cocos2d::ui::PageViewIndicator::reset(long)”, referenced from:
cocos2d::ui::PageView::onItemListChanged() in libcocos2d tvOS.a(UIPageView.o)
“cocos2d::ui::PageViewIndicator::create()”, referenced from:
cocos2d::ui::PageView::setIndicatorEnabled(bool) in libcocos2d tvOS.a(UIPageView.o)
“cocos2d::ui::PageViewIndicator::indicate(long)”, referenced from:
cocos2d::ui::PageView::doLayout() in libcocos2d tvOS.a(UIPageView.o)
cocos2d::ui::PageView::moveInnerContainer(cocos2d::Vec2 const&, bool) in libcocos2d tvOS.a(UIPageView.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

In init I just load scene and add it:

root = CSLoader::createNode("MenuScene.csb");

addChild(root);

Please, don’t change my sample project. Just set the COCOS2DX_HOME to the location of cocos2d-x and launch it. You don’t have to add anything manually.

I tried that, but then I’m getting error that cocos2d.h cannot be found (from Prefix.pch).

edit:
Then I saw red libcocos2d tvOS.a in Frameworks so I’ve added it.

If cocos2d.h can not be found, then you have a wrong COCOS2DX_HOME path. Please fix it and try again.

Ofc I did it first:

iMac-Piotr:cocos2d-x piotr$ pwd
/Users/piotr/Documents/pierdoly/cocos2d-libs/cocos2d-x
iMac-Piotr:cocos2d-x piotr$ ls
AUTHORS cmake plugin
CHANGELOG cocos setup.py
CMakeLists.txt docs templates
CONTRIBUTING.md download-deps.py tests
README.cmake extensions tools
README.md external web
build licenses

edit: Success! I just downloaded your sample and it’s different from older one. Now it builded.

However still no word from apple tv remote as well as linker is throwing the same error about CSLoader, which I described before.

Apple remote is not working on AppleTV simulator. What linker error did you get?

Undefined symbols for architecture x86_64:
“cocostudio::Light3DReader::createInstance()”, referenced from:
cocos2d::CSLoader::CSLoader() in libcocos2d tvOS.a(CSLoader.o)
“cocos2d::StencilStateManager::onAfterVisit()”, referenced from:
cocos2d::ui::Layout::stencilClippingVisit(cocos2d::Renderer*, cocos2d::Mat4 const&, unsigned int) in libcocos2d tvOS.a(UILayout.o)
“cocos2d::StencilStateManager::onBeforeVisit()”, referenced from:
cocos2d::ui::Layout::stencilClippingVisit(cocos2d::Renderer*, cocos2d::Mat4 const&, unsigned int) in libcocos2d tvOS.a(UILayout.o)
“cocos2d::StencilStateManager::onAfterDrawStencil()”, referenced from:
cocos2d::ui::Layout::stencilClippingVisit(cocos2d::Renderer*, cocos2d::Mat4 const&, unsigned int) in libcocos2d tvOS.a(UILayout.o)
“cocos2d::StencilStateManager::StencilStateManager()”, referenced from:
cocos2d::ui::Layout::Layout() in libcocos2d tvOS.a(UILayout.o)
“cocos2d::ui::PageViewIndicator::setDirection(cocos2d::ui::ScrollView::Direction)”, referenced from:
cocos2d::ui::PageView::setDirection(cocos2d::ui::ScrollView::Direction) in libcocos2d tvOS.a(UIPageView.o)
cocos2d::ui::PageView::setIndicatorEnabled(bool) in libcocos2d tvOS.a(UIPageView.o)
“cocos2d::ui::PageViewIndicator::setSpaceBetweenIndexNodes(float)”, referenced from:
cocos2d::ui::PageView::setIndicatorSpaceBetweenIndexNodes(float) in libcocos2d tvOS.a(UIPageView.o)
“cocos2d::ui::PageViewIndicator::reset(long)”, referenced from:
cocos2d::ui::PageView::onItemListChanged() in libcocos2d tvOS.a(UIPageView.o)
“cocos2d::ui::PageViewIndicator::create()”, referenced from:
cocos2d::ui::PageView::setIndicatorEnabled(bool) in libcocos2d tvOS.a(UIPageView.o)
“cocos2d::ui::PageViewIndicator::indicate(long)”, referenced from:
cocos2d::ui::PageView::doLayout() in libcocos2d tvOS.a(UIPageView.o)
cocos2d::ui::PageView::moveInnerContainer(cocos2d::Vec2 const&, bool) in libcocos2d tvOS.a(UIPageView.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This remove won’t work? So how I can test it :smiley: ?