Thursday Discount - Lifetime Access for $20!!!! - Click Here!

An introduction tutorial to tvOS and Sprite Kit

An introduction tutorial to tvOS and Sprite Kit
September 19, 2015 Justin

An introduction tutorial to tvOS and Sprite Kit

Its a whole new era for iOS game developers when the new Apple TV is launched. With some minor tweaks our SpriteKit based games easily be played on the Apple TV natively. In these video tutorials we’ll look at some key changes you’ll need to make to work with the new touch-senstive Apple remote. These are Swift 2 based tutorials and require a minimum of Xcode 7.1 to test in the Apple TV simulator. And fear not folks, eventually we’ll work with some external game controller code, but currently the Apple TV simulator does not support game controller testing. But there’s still plenty to enjoy in this new series of video tutorials on the tvOS.

This video tutorial is an introduction to using Swift 2 and SpriteKit in a tvOS app. Apple provides some convenience methods for focusing in and out of UIViews in a tvOS app, but when it comes to SpriteKit apps, us resourceful game developers need to do a little extra work. You’ll learn how touch anywhere on the new Apple TV Remote’s touch pad and navigate buttons, bring one into focus and keep it selected (to potentially choose as a selection). Along the way, you’ll also learn some basics in Xcode 7 for setting up an osTV app, like importing resources, setting the game scene size, etc.

This content is restricted to buyers of The CartoonSmart Subscription.

Can’t see the video above? Bummer.  Consider subscribing to CartoonSmart for full access!

In this lesson we will focus on adding gestures recognizers to detect taps, selection “clicks”, specific button presses (for example, Menu or Play / Pause) and gesture recognizers. We’ll also discuss removing gesture recognizers and transitioning scenes.

No time for video tutorials today?

Here’s a little glimpse of what’s involved in setting up a SpriteKit app for tvOS. First some good news. SpriteKit for tvOS is for the most part just like SpriteKit for iOS. So yes, all those awesome SpriteKit lessons you’ve been enjoying here at CartoonSmart will carry over. Some minor exceptions I’ve noticed so far…

  • No rotation gestures
  • No multiple finger touches
  • You can’t touch the TV screen

Okay, that last one isn’t so minor!  It can make a huge difference in your game for example, if your app heavily relies on the touchesMoved statement to say, lift an object and put it into place, that might not translate over to tvOS so well. You can still use the touchesMoved statement with tvOS, but you have to consider that the user is sitting on their couch 10-15 feet away from their television and more importantly, they are probably using the relatively small touch surface of the remote to navigate your app. Yes, a device could substitute for the Apple TV remote, but assuming they are using the new Apple TV remote, it is a far smaller surface to move one’s finger across. So apps requiring a high level of precision maybe need some rethinking to be fun on the new Apple TV.

Also every time the user touches the remote they are touching the middle of the screen. For example, on a SpriteKit scene that is sized for the Apple TV at 1920 by 1080, touching anywhere on the remote will return 960, 540 as the initial touch location.

CGPoint locations on the new Apple TV Remote and tvOS

So from there, you could move your finger to a location relative to that initial starting point. But if the user started touching on the far right of the remote, they will be limited in how much of the right side of the screen they can access (Apple TV users will of course learn the finer points of using the remote to access any portion of the TV). Point is, this does change drastically how users will interact with menus and buttons in your app.

But once users get into the “main game” part of your app, they can use directional swipes (left, right, up and down) as usual to move a character, and Apple has added options for Tap gestures to detect taps in the up, down, left or right portions of the remote touch pad.

Plus you can program the Play / Pause button to do actions in your app, and of course tapping / clicking anywhere in the remote’s touch surface can perform an action as well.

So yes, there’s some changes in the way we’ll control characters and navigate an app, but beyond that the core engine of most SpriteKit games can stay the same.

 

Download the project files…

This content is restricted to buyers of The CartoonSmart Subscription.

Can’t download?  Consider subscribing to CartoonSmart for full access!

 

Never lose your place.

Sign up for the newsletter to get a free CartoonSmart account and track your progress in every course.

I'm cool. Sign me up!




Know what an affiliate program is? You make money just by sharing links to our site! Win. Win.

Earn when you refer any buyer here! 30 day tracking. Commissions are 33%-50% and recur on subscription products!