AppleTV support

Ok I figured out closing app problem:

In RootViewController.mm:

-(void)pressesBegan:(NSSet*)presses withEvent:(UIPressesEvent *)event {
    
    UIPress* p = [presses anyObject];
    
    if (p.type == UIPressTypeMenu)
    {
        if(cocos2d::Director::getInstance()->getRunningScene()->getName() == "menu"){
            [super pressesBegan:presses withEvent:event];
        }
    }
}

-(void)pressesEnded:(NSSet*)presses withEvent:(UIPressesEvent *)event {
    
    UIPress* p = [presses anyObject];
    
    if (p.type == UIPressTypeMenu)
    {
        if(cocos2d::Director::getInstance()->getRunningScene()->getName() == "menu"){
            [super pressesEnded:presses withEvent:event];
        }
    }
}

And ofc set first scene as ā€œmenuā€.

edit:

Btw I just wanted to create archive and got error that libcocos2d tvOS.a is compiled without bitcode. I had to add OTHER_CFLAGS="-fembed-bitcode" in line 160 (build.sh). Then it worked.

edit:

app sent and waiting for review. Many thanks to @elvman

Again, if you would look closer at my tvOS sample (https://github.com/elvman/tvos-test/blob/master/proj.ios_mac/tvos/RootViewController.mm line 98), you would see that I already did this (but using tags, because integer comparison is a bit faster and more typo-proof than string comparison).

Hi Iā€™m having the same problems as piotrros (on both simulator and device), Iā€™m using your project as it is, using COCOS2DX_HOME, could you try adding a ā€œcocos2d:ui::Buttonā€ to MainMenu.cpp? that seems to trigger these errors:

Btw I can compile and test on both the simulator and on device by not adding a cocos2d::ui:Button. So Im not sure why it doesnt work when I add that.

Undefined symbols for architecture x86_64:
  "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)

Well I donā€™t know why it isnā€™t working, but from most UI you wonā€™t get any benefit. Like ui::Button - it wonā€™t trigger clicking anyway. So I abandoned loading scene from studio and did everything from code. Itā€™s not most comfortable solution though.

Yeah I would too but all my game ui is made using ui::Buttons, mainly to use the scale9 stretching, last time I saw it was available only to ui:: widgets.

Found the error, actually Iā€™m not sure its an error, perhaps this was done on purpose? but the ui/widgets/UIPageViewIndicator.cpp and base/CCStencilStateManager.cpp were not marked as part of the tvos target, on the cocos2d_libs project.

1 Like

I am following the same stepsā€¦but it throws an error

cocos2d-xtvos-branch/cocos/platform/CCImage.cpp:59:10: fatal error: ā€˜png.hā€™ file not found
#include ā€œpng.hā€
^
1 error generated.

I did the following steps:

  1. Download sample zip from https://github.com/elvman/tvos-test.
  2. Clone the cocos2d-x tvOS branch using command ā€œgit clone --depth 1 https://github.com/elvman/cocos2d-x/tree/tvos --branch tvos --single-branch cocos2d-x-tvosā€
  1. Download the build script and put it in cocos2d-x-tvos/build
  2. Go to the cocos2d-x-tvos path from terminal.external folder have only one file config.json
  3. Run ./download-deps.py it download the content of external folder.
  1. Go to build folder: cd build.
  2. Run ā€œ./build.sh -p appletvā€.

Build is not success. Throwing error cocos2d-x-tvos/cocos/platform/CCImage.cpp:59:10: fatal error: ā€˜png.hā€™ file not found.

I see under /cocos2d-x-tvos/external/png/include there are four folder android, ios, mac, win32 and all folder have png.h. where is the tvos folder?

Please suggest how to solve problem? and where I did mistake?

Thanks Anjan Kumar

How to get called menuPlayCallback method. I am running app on Apple Tv 4th generation device. I was not be able do detect MenuItemSprite is focused and touched. How to move remote point to that button.

Please suggest how to get click listener on menuitem sprite.

I am running this sample on real device. Sample is running but I will not be able to get call MenuItemSprite click listener function. How to move remote to menu item place. I move the finger on remote and I got the log of key up, left, right, down with value but not getting selecting effect on MenuItemSprite (Blue Color).

May Be I am missing anything in use of remote. Not getting select hint so user can see whether he is on screen.

Please give me some clue to I will start further working.I am stuck on this.

Without MenuItemSprite click listener how we navigate between screens.

In device user direct touch on screen, In apple Tv user doesā€™t getting any like mouse point so user click on it.

I have odd behavior on this. When I exit the app using MENU then start it again and then press the MENU again it will ALWAYS exit the app even if [super pressesBegan:presses withEvent:event] is NOT CALLED.
Do you have similar behavior? Any idea what is going on?
Thanks!

This is awesome!

Does anyone know if Cocos2d-x will officially support tvOS?

@elvman It is very impressive how you put all of this together.
Iā€™ve played around with it some and have the sample working.

Only issue was that for some reason tvOS doesnt like UIKeyboardWillShowNotification, UIKeyboardDidShowNotification, UIKeyboardWillHideNotification and UIKeyboardDidHideNotification, so needed to comment the use of those out in CCEAGLView-tvos.mm.

Iā€™m just getting started with tvOS, so havenā€™t looked into tvOS requirements yet.

Have you looked into changing the tvos/RootViewController into a subclass of GCEventViewController and then setting controllerUserInteractionEnabled = NO to trap menu button presses to prevent exiting the app when you are showing a scene that should not exit the app?

This video has some info at about 18:00 that discusses how to manage exiting your app as described above. Not certain yet if elvmanā€™s sample app is 100% compliant with trapping menu button calls and preventing the system from exiting the appā€¦ I will be testing that soon.

A related issue that I am also working on is that sounds are not playing properly after exiting the app and then resuming it.

Did you read this thread?

There is no substitute for getting your hands dirty. You will understand the work you did to get there. Seriously. No joke, not trying to be a smart ass. But asking for a handout in a thread that clearly accomplishes what you want probably seems naive.

I can not compile the project with CocosDenshion support.
I see that the support is there but I get this linker error:

Undefined symbols for architecture x86_64:
  "CocosDenshion::SimpleAudioEngine::getInstance()", referenced from:

Would you know how to fix it?

FIXED by adding all cocos/audio/ios files into cocos2d_libs project.
Also needed to update CDAudioManager files from the link shown in header of this topics.
Thanks!