Building for the new AppleTV / tvOS

Thanks @elvman; I’m trying to find it in the configs but there nowhere is any note about -fembed-bitcode.
This settings is likely default for AppleTVOS target, but I nowhere see this target to be set neither.

Please give me a hint. Where do you set the AppleTVOS target (Xcode complains if the lib is not compiled for AppleTVOS target) and where do you set the -fembed-bitcode option.

I believe that I have the SpiderMonkey compiled ok so this would finalize the cocos-js branch for tvos!

I’ve modified tvos.ini last two lines like this:

cfg_build_release_mode="-O3 -DNDEBUG -fembed-bitcode"
cfg_build_debug_mode="-O0 -g -DDEBUG -fembed-bitcode"

and that helped (I believe). Now I have tons of different bugs :wink:

Please help me out. I’m really struggling with compiling SpiderMonkey for tvOS.
I’ve opened a now thread for it: Help with compiling SpiderMonkey for tvOS
Thanks a lot!

Today I fully ported the sound engine to tvOS. You can still get the cocos2d-x tvOS port here: https://github.com/elvman/cocos2d-x/tree/tvos

3 Likes

Hawkwood, indeed you did a great job but please suggest us the same for cocos2d-x version 2.2.6.

Further, in your shared code we found many things distinct what come with cocos2d-x 3.8(Standard Compressed File) like TvOS folder, new EAGL view, etc. Please guide us how you did that as we tried the same python file as well checked the XCode setting with no luck.

Look forward to hear from you soon.

Thanks,

Any chance of a working menu for the Siri remote? I am rolling my own, very custom, solution right now, but would love to extend the menus so I am in need of a more generic approach. What is your approach so far?

The remote’s menu button must pause the game (https://developer.apple.com/library/tvos/documentation/General/Conceptual/AppleTV_PG/WorkingwithGameControllers.html) and exit it (Apple rejected my app, because it did not exit the app from main menu).

I implemented the exiting with menu button in my tvOS sample (https://github.com/elvman/tvos-test). Please look at tvos/RootViewController.mm line 115.

Hi guys,

We’re really excited to announce our first game for Apple TV. It’s called Song of Pan and it’s online on the store. Obviously the game is proudly made with cocos2d-x and we want to thank the whole community and in particular @elvam that with its porting work has enabled us to release the game in record time.

About the Game :

Come along on an Epic adventure through the slopes of Mount Olympus.

In this puzzle platformer, you play the role of Pan, a young satyr who must recover Zeus’ flock of sheep through the use of his enchanting flute. Use strategy to collect music notes that will activate your flute. Solve complex puzzles to make a safe pathway for the sheep. Choose your steps wisely as you navigate through groves, rocks, ruins & cliffs and herd the sheep to safety.

On this journey, there are many trials and tribulations you will encounter. What rewards will you reap as the result of your accomplishment? The Gods may have a bigger plan in store for you, Pan.

The Apple TV version of Song of Pan can be played at no cost. A premium upgrade is available that will enable the ability to save the game’s progress with a one-time in-app purchase.

I really hope you enjoy the game.

1 Like

That artwork is awesome. Great to hear that there is a cocos2d-x product out there on the App Store now! Good choice on the IAP, I think it worked really well for Does Not Commute. I will try your game today and flood you with questions on specifics :wink:

Good luck!

Please someone assist us over the same.

I have no idea what you need assistance with, could you clarify what you are trying to do and how? What code base are you working with (@elvman or @hawkwood)?

Thanks ‘digitalhoax’.

We tried with @hawkwood and in it we downloaded the shared code. After downloading we compared what we require in our project but mashed with TvOS folder and really surprised how it seems in sample code. What dependencies we will require to do in our existing code. Our version for Cocos 2d-x is 2.2.6.

Please assist us by sharing the steps to port existing cocos2d-x 2.2.6 game project to TvOS.

Look forward to hear from you soon.

First I’d like to thank everyone, especially @elvman and @hawkwood, for preparing the code base for tvOS. I got it up and running on my dev kit in no time and am now coding away on my first tvOS app. :smile:

@digitalhoax : regarding doing a menu, I decided to not overthink it. I just keep track which item is selected, detect any swipes, and change the visual appearance of the menu buttons accordingly. For example the not selected menu items are smaller and more transparent than the selected one. My app will be available on iOS as well, so I just use the same menu buttons just with the normal tap events.

I did run into a strange issue though with the remote. I’ve implemented the EventListenerController as described earlier in this thread, and am receiving the “keys” from the remote. To check if the user has swiped, I check in the onKeyDown callback if the keyCode equals cocos2d::Controller::BUTTON_DPAD_LEFT or cocos2d::Controller::BUTTON_DPAD_RIGHT. This works but somehow when swiping for example to the right, the onKeyDown callback also receives the BUTTON_DPAD_DOWN keycode at the same time.
The same applies when swiping in the other directions - always another keycode of a different direction is received as well.

Did anyone experience this issue, and found a solution or logical explanation for this behaviour?

I think if I was you I would rather port the game to a current cocos2d-x than porting cocos2d-x v2.x to tvOS. You might be able to apply the changes @elvman and @hawkwood committed to the v3.x branch anyways, but there might be other parts that you need to rework.

@netunlimited Yes, I am doing the same thing for menus now. I have done some tests with a tilt effect like the tvOS menu does, but wasn’t happy with the outcome yet, so leaving this for later. About the input: I am doing buttons via the key events (obviously) but am not using the dpad, but rather the touch input. I find the dpad very irritating and I think it has a bad UX. I don’t think the dpad events will give you reliable swipe events as they are meant to be taps (touch, not click) on the corresponding areas of the touch area. You should probably just detect swipes yourself via the touch moved events.

@digitalhoax: You’re right, the dpad doesn’t make sense that way.

I initially went for a touch implementation, however for some reason I don’t receive any touches from the remote. I tried the code from this sample project:

And it just doesn’t do anything when I swipe or touch on the remote. None of the callbacks are called.
[Edit] After some more attempts, the code does seem to work, but only when I don’t add my Cocos Studio node to the HelloWorld scene like here:

rootNode = CSLoader::createNode("MainScene.csb");
addChild(rootNode, 2, "rootNode");

No clue why that breaks the touch listener… :frowning: [/Edit]
[Edit2] Figured it out. Apparently the CS node swallows all the touches. What I did was disable the “Touchable” property for all menu items in the Cocos Studio editor, and that was enough to get my listener working. [/Edit2]

Another thing, did you manage to properly setup the “menu” button behaviour? Right now it always goes back to the Home screen, but in my app it should do that only in the main menu scene, not in other scenes.

After a few hours of experimenting, I found that the solution for capturing the menu button is luckily surprisingly simple! Just add this method to RootViewController.mm:

-(void)pressesBegan:(NSSet*)presses withEvent:(UIPressesEvent *)event {
    if( ((UIPress *)[presses anyObject]).type == UIPressTypeMenu) {
        if (self.canExitApp == YES) {
            NSLog(@"Menu button: Default behavior, back to Home");
            [super pressesBegan:presses withEvent:event];
        } else {
            NSLog(@"Menu button: Custom behavior, go to other Cocos2D scene");
        }
        return;
    }
}

“self.canExitApp” is of course a BOOL which you should set yourself based on your Cocos2d-x’s scene state. That’s all. Enjoy :slight_smile:

Actually you could save time and just look at my tvos-test app:

Ouch :slight_smile: I looked everywhere except there…

I ported all the cocos2d-x tests to tvOS in this PR:
https://github.com/cocos2d/cocos2d-x/pull/14808

what’s missing is to add support for the controller so we can navigate the menus.