125 iPS GameplayKit with Jake Gundersen

00:00 0:49:05
Download MP3

01:04 - Jake Gundersen

01:38 - GameplayKit Framework Reference

03:56 - What’s the advantage of GameplayKit?

09:05 - Component Architecture

11:52 - ComponentKit | Component API

14:29 - Randomization

16:21 - State Machines

24:10 - Rules Systems

24:51 - Pathfinding

30:50 - Agents, Goals, and Behaviors

33:58 - Compatability

35:54 - Cross-platform LimitationPicks

fastlane (Andrew)Swift State Machines (Andrew)Ryan Olson: Libraries Used in the Top 100 iOS Apps (Andrew)Charles Max Wood "Upgrading From Yesterday" (Chuck)Charles Max Wood: UFY 007: Standing Desk and Upgrading My Health (Chuck)A Simple, Portable, Inexpensive Standing Desk Solution (Chuck)Periscope (Chuck)Ray Wenderlich: Introducing the iOS 9 Feast! (Jacob)The Life-Changing Magic of Tidying Up: The Japanese Art of Decluttering and Organizing by Marie Kondo (Jacob)

Transcript

**[This episode is sponsored by Hired.com. Every week on Hired, they run an auction where over a thousand tech companies in San Francisco, New York and L.A. bid on iOS developers, providing them with salary and equity upfront. The average iOS developer gets an average of 5-15 introductory offers and an average salary offer of $130,000/year. Users can either accept an offer and go right into interviewing with a company or deny them without any continuing obligations. It’s totally free for users, and when you're hired they also give you a $2,000 signing bonus as a thank you for using them. But if you use the iPhreaks link, you’ll get a $4,000 bonus instead. Finally, if you're not looking for a job but know someone who is, you can refer them on Hired and get a $1,337 bonus as thanks after the job. Go sign up at Hired.com/iphreaks]****CHUCK: Hey everybody and welcome to episode125 of the iPhreaks Show. This week on our panel we have Andrew Madsen. ANDREW: Hello, from Salt Lake City. CHUCK: I’m Charles Max Wood from Devchat.tv and we have a special guest this week and that’s Jake Gundersen. JAKE: Hello, also from Salt Lake City. CHUCK: You want to introduce yourself? JAKE: Yeah. So I am Jake Gundersen. I have been doing iOS development for almost five years. People might know me just from – I’m on the Ray Wenderlich podcast. I’ve participated in a number of Ray’s books and I do – I’m just a contract developer so I just take gigs from wherever they come. I’m independent so I usually manage several clients at once and actually worked with Andrew for a couple of years at Mixed In Key so we know each other pretty well. We were friend before that. CHUCK: Hire Jake please! So we brought you on to talk about GameKit. Do you want to give us a brief overview of this? ANDREW: I’m going to insert a correction because that’s my fault but we’re going to talk about GameplayKit. CHUCK: GameplayKit. ANDREW: Different than GameKit. JAKE: Yeah, I was just going to say that. So yeah, the GameplayKit is a new framework in iOS 9. It’s independent. Most people are going to use it in conjunction with either SpriteKit or SceneKit. It’s a set of tools for making games but it’s independent. You could use it in an app if there is something particular area you needed. So it’s not married to any particular other framework; it’s this independent thing. But as I said, it’s just a handful of tools usually for making games. So one of the big things in there is an entity component architecture system. So in any component architecture something you usually would use with games instead of an inheritance architecture or NBC. And they're not mutually exclusive; there’s an overlap between all of those three but it’s a more common way to structure an architect’s games. There’s also a handful of other things. There’s as suite of random number generators, different kinds of random number generators. So then random number generators, there’s different – some of them are more resource intensive and give you different kinds of randomness so you can pick and choose how random you need your numbers to be. What else are in those? A handful of things. I think there’s an A* implementation in there. I haven’t looked deeply into that yet. There’s a min-max stuff for AI. It’s just a podge of tools for making games. ANDREW: There’s a state machine API which I actually think is really interesting personally because I know about state machines but also because it’s actually a really general thing. It has nothing specific to do with games. State machines are useful in games, right? So that’s one of the things I thought was kind of cool. JAKE: Yeah, the state machine is really nice. A lot of people are just writing their own state machines to make games but it’s nice to have a blessed implementation of that from Apple that comes with a sample code to say this is how they envision where a state machine would go. And it’s interesting because I wrote the platformer game starter kit for Ray Wenderllich and I did most of the things that are in this new GameplayKit but looking at how GameplayKit does it, there’s definitely some improvements over what I did in my starter kit. CHUCK: So I guess the question is what’s the advantage of GameplayKit over just regular programming? Is there some kind of performance optimization or do they give you better algorithms for things or you just don’t have to invent on your own? Or is it more just the – it’s more native-ish? JAKE: Yeah, I would say the benefits are probably all of those things. I think the biggest on especially for beginners or people that are maybe accomplished developers but haven’t worked with games is that you don’t have to go out and figure out how to do it. The sample code becomes with GameplayKit is going to show you how to architect a more complex game system. And so rather than having to go out and read blogs and different things that are kind of unrelated to Cocoa – usually Cocoa is not the first place people go when they want to make games. And so you have to go, you have to learn about how a state machine is implemented in a game. You’d have to go out and learn how to implement a component architecture in a game, and now you don’t have to; it’s just – this framework, it comes with it. So for people that already don’t necessarily know, this is the best way to do it. It’s now obvious because it’s built right into the Cocoa frameworks, right? There are some performance benefits to some of the random number generators and stuff. I don’t expect that their implementation of a state machine is way more performant that just a naïve implementation of a state machine because it’s usually not a performant bottleneck. I could be wrong about that but I wouldn’t expect huge performances in that or in the component architecture system. But definitely, some of the specifics they are – I’m sure that they optimized. I know it specifically with randomization that they give you lots of choices and tell you ‘these are faster and these are more random’. I also think just having it already done for you, not having to do it yourself, spend the time doing it with yourself which a lot of it is just really standard stuff. If you have been making games for a while, you know –. For example, a state machine – a good use of a state machine is a state machine’s going to drive the animations. So I’m probably going to use a platformer game as my reference point as we talk about this because it’s the only thing I’m the most familiar with. But the state machine drives the animation so when you're jumping, you run a different animation that when you're walking or when you're running or when you're attacking, right? And so each of those different animations are either a series of still frames that you run through like a video. Or they can also be a series of – sometimes, the way you do animations is by breaking your character up into arms and legs and head, and the way you animate them is you move or scale or whatever each component, then you can generate animations that way. So when you want to switch from one animation to another, a good way to do that is just to look at the state machine and say, “Okay, am I jumping? Am I running,” and then as you change from one state to another you trigger those different animations to play. So state machine is a very nice, well-structured way to control character animations in a game. CHUCK: Yeah, I can also see that maybe on like a tower defense game where you're turret is turning or firing or something like that. JAKE: Exactly. Yeah. ANDREW: I was going to say – going back to Chuck’s original question – I think there’s a lot of value especially for new people in well-designed APIs. It could be on the advantage of them actually doing some of the work for you and just meaning you have to write with code. I think they can also guide you – you kind of hinted the shape – but they can actually guide you toward an architecture that actually makes sense. And sometimes those architectural choices which are really important are some of the hardest things when you're new to a particular problem. So they enforce a structure on your code that makes sense that you might not have otherwise. And I think that could be, particularly for some of this logic stuff because it’s like game logic the GameplayKit. It helps you implement that – it helps guide you toward a good architecture for your logic. JAKE:**I agree. I think that’s one of the biggest benefits. And even if you're – I see a lot of times, developers that are – very experienced developers that have been writing apps for years, but when the game space is different enough and if they haven’t been exposed with it before, they will have a tendency to fall into using architectural structures that they're familiar with from apps. And a lot of times you can dig yourself a whole that makes what you're trying to accomplish more difficult because you're using delegates or something that does not really makes sense. Delegates can make sense but just as an example, if you're using a delegate and you’ve got three or four different – you’ve got a [inaudible] of your main character and then you’ve got an object representation of your main character and you’re using delegates to communicate back and forth. That makes sense in an app architecture but that’s a lot of overhead and unnecessary complication and it isn’t necessarily – it doesn’t necessarily make your game better to break those things up and not weigh the same way it does with an app. And so having the component architecture in GameplayKit, it’s like one of the first places now when people go to build games; that’s where I’ll go first and I totally agree with that. It’s great to have that. Unity for example – I’ve been learning that lately and it – the whole thing of its component architecture and it’s the first real deep exposure. I’ve heard of component architecture before but I’ve never used it as that time but as I’ve been learning Unity, I’m starting to appreciate how it breaks gaming [inaudible] and code into parts that become re-useable but in a way that makes sense for games.**ANDREW: I’d like to dig in a little bit to this specific parts of GameplayKit. One thing that you mentioned right at the beginning was that there’s this component architecture. Can you explain a little bit about what that means because when I hear component architecture – component is a really generic word. Component just means a thing basically, right? A part of a whole and so when I hear component architecture, it essentially means nothing to me. So I’m curious to know what that really means in terms of game development and what this system helps you do. JAKE: Yeah, so it is a little difficult to understand especially if you haven’t been exposed to the alternatives, like anything with coding, right? But I do the best I can. So generally, in – again, I’ll use my own platform or game kit as an example – when I first wrote that, I used an inheritance architecture. For example, I wrote my own physics engine to handle collisions and gravity and jumping and running and all that stuff. And the physics engine code applies to both the – to anything that’s a physics object in the game which, in my case, is the main character primarily but it also applies to enemies, and it also applies to some of the objects like in power ups and things that exist in the world. So I needed to write code that said ‘don’t allow the character to walk through a wall or to fall through a floor’ and then that same code needs to apply to enemies and that same code needs to apply to game objects. So I use an inheritance architecture. That worked but I ran into the exact problem that was laid out by the docs and by some of the posts that have been written about game – about component architecture. You end up with really heavy super classes. So you're writing all these physics logic and collision detection and because it’s shared across all these different objects, you end up with this giant super class object that handles all those things, right? So in a component architecture, instead of inheriting, you use composition and so you write a physics object component and then the game character owns a physics component – owns one of those objects and each enemy character owns one of those objects. And so the only thing that needs to be in that physics object is a physics detection and collision stuff logic, and then everybody use it when they need it and gain objects when they don’t need it, don’t have to have it. Does that make sense? That’s kind of the primary difference and that’s the primary reason you use it is because otherwise, you end up with really heavy – code heavy super classes and lots of branching in those super classes. ANDREW: Yeah, that helps. JAKE: So you’ll have a rendering object that generically renders Sprite and you’ll have a physics component and then you’ll have – you might have a life component that handles keeping track of how much life the player has left and maybe enemies, too; things like that. ANDREW: So related to the thing we were just talking about, how does that component it API in GameplayKit really benefit you? Why can’t you just organize your code using this architecture yourself? What does an API do for you? JAKE: You can. You can implement it yourself. It just gives you a standard way of doing it. It’s not obvious how to – for example, most games are driven by the render loop, so 60 times a second you're going to draw to the screen and you usually want to run all your logic right before rendering 60 times a second. And in SpriteKit for example, that’s broken up into different – you’ve got different entry points into the render loop. So you’ve got before physics run, after physics run, before animations run, after animations run, etc. So it’s not obvious where – when you structure your component kit system – it’s not obvious where you – how do you update all the components when you say you’ve have a player and he’s got physics engine component, he’s got a render component, he’s got an animation component – whatever. How do you connect all of those components because each of those – the logic in each of those components needs to be run at certain time so the component API takes care of some of that for you. And it’s not – it wouldn’t be super hard to figure that out and write it yourself but it’s like you don’t have to. It’s already done in a standard way. ANDREW:**Okay. Interesting. I’m actually reading – I’m actually skimming though the documentation [chuckles] for the component stuff and one thing it says is instead of organizing a game’s object module in terms of what each game object is, the entity component pattern encourages you to think about what each game object does; I don’t know, that’s size.**JAKE: So the classes in GamplayKit are GK entity and GK component. So each thing in your game is going to be an entity and then it will – you will add some number of components to it for whatever logic you need it to run. Then each component has – it looks like an update with delta time method on each component. ANDREW: Okay, components are essentially like a block of functionality so it’s something that an entity might do and multiple different entities will share components because of this – do the same thing, right? Your character and enemies, even though they're different, they both have to know how to move or shoot at each other or something, right? JAKE: Right. ANDREW: Cool. That makes some sense. CHUCK: I like the idea of a composable or modular design to these so that you can easily share functionality between the different entities into your system. JAKE: Right. CHUCK: I want to veer into randomization. I guess as a casual – I don’t want to say casual – but as non-game programmer, most of the time I’m just using whatever random number generator is provided by the framework or programming language I’m using. So why do you need different types of random for games? JAKE:**I’ve run through this API really quick but I’m just going to tell you what I know but it might not be 100% accurate. The basic idea which is accurate is that different random algorithms are more or less random and they are more or less resource intensive. So depending on what you're trying to do, you might – the level of randomness might not be random enough for me, not feel quite right. The other thing besides just being more or less random and more or less performant, you can also use different distributions so there’s the seeker of distribution where things kind if [inaudible] versus a uniform distribution. So you can think about as you develop – and this is – a lot of this is either procedural generation of levels or for AI behaviors – you don’t want an enemy AI to always behave in exactly the same way you want [inaudible] to be some variation in how it behaves. And then – so you give it these rules but then it adds some randomization in there. Maybe you want that randomization to be a uniformed distribution so it has an equal – it’s equally likely that it will do one of four basic behaviors. Or you might want it to do certain things way more often than other things and that’s where the distribution comes in. It just gives us more because the arc for random is the one I always use in most of my code but there are times when that’s not – maybe it’s too resource intensive or whatever; it’s not quite random enough. There are times when that’s not the best choice and so the randomization classes in Gameplay give you more options.**CHUCK: Gotcha. Should we talk about state machines? I think we all have an idea of what they are but I don’t know if all of our listeners will. ANDREW: Yeah, I’d love to talk about state machines because I think this is an interesting part of game kit – maybe a lot of GameplayKit is actually useable in non-game apps but this is the thing that stuck out to me as really –. It’s important in games but I’ve used state machines in apps that I have written before. CHUCK: Yeah, I have as well. And the idea basically is you have several states with particular rules for how an object or entity moves from one state to the other. That’s essentially what a state machine is. ANDREW: Right, so – go ahead Jake. JAKE: Yeah, it might be worth injecting at this point that a state machine – one of the rules of a state machine is that you can be in one state – only one state in any given time. So that’s important to keep in mind as you think about ‘how would I use this’ because you can’t – the idea of a state machine is that the states don’t mix together. You have one and only one state and you can be in that state or another state but that’s how a state machine works. CHUCK: Yeah, and so for example you could go from flying to driving and the transition is when you reach elevation zero or something like that where there are particular things that cause your entity to move from one state to the other. And it can be defined however you want depending on what your game has to do. JAKE: Right. The classes that Apple provides are the GKState and GKStateMachine classes and then on a GKStateMachine, you’ve got all these methods like ‘can interstate’, ‘interstate’. So you can set up logic that says ‘from this state, I can only enter these three states of the eight states available’ and then you’ve got an interstate method so that you can, like you just mentioned, you can handle transitions. Again, it’s not something you couldn’t write yourself but it gives you a nice, complete implementation that you can start with. And if you're unfamiliar that’s a huge help. CHUCK: Yeah, the state machine libraries that I’ve used in other languages I usually wanted it to be wrapping in something else. So instead of directly calling whatever entity – ‘go to the next state’ – I can’t remember exactly what the name of the method was but instead of going ‘go to the next state’ what I say is – so it intercepts a button press where you tap on the screen on your iOS device and that triggers the hero.jump method and that jump method then speaks to the state machine and tells it to transition. JAKE:**Right. [Crosstalk]**CHUCK:**And then that way I [inaudible] what it is but what it actually does, so what you see on the screen is the name of the method.**JAKE: Yeah, and in my – again – in my platformer’s game, I use the state machine but the way I structured the code was more naïve and so I had a lot of code in an update method. I wrote a lot of logic just writing the update method. So for example, if you are running on the ground, you are in this running state and you were running – it was doing a running animation and then you hit the jump button. The first thing it looks for is it checks to make sure you're on the ground because you can’t jump out of mid-air, and so if you're on the ground then you knew you're in this running state. I actually checked whether I was on the ground and some places I checked the state I was in in other places; I checked the conditions that would indicate what state I was in but the nice thing about GameplayKit is it puts more structure around that and so you just say ‘if I’m in a running state and I hit the jump button, I know that I can’t enter the jumping state because I’m in a running state’. And if I wasn’t on the ground I would have been in a falling state and so that’s when I can’t jump is when I’m in this falling state. So again, the GameplayKit puts more structure, more – it’s just a cleaner implementation of, let’s say, the one I did which was – the game I built was not complicated enough that it wasn’t understandable but if it did get much more complicated than having this cleaner, more structured state machine implementation is that’s when it really starts to help and it helps not to be confused and lost with what you're doing. I have seven or eight states and that was enough. As I was building it there were several times where I made mistakes because I had a double jump state. You can only enter the double jump state from the jumping state or the falling state and that got a little tricky. ANDREW: I like the – if you look at the GamplayKit state machine API, it’s actually really simple. There are just two classes; there is GKStateMachine which represents a state machine and then there’s a class called GKState that I think you're supposed to subclass. There really are not that many methods on GKState. You just have a ‘can enter’ state method that returns yes or no depending on whether the state passed in. there’s a valid transition from the current one but then they also have the update with delta time method which, I suppose, that is specific to games so that you can actually do your –. I don’t know what you call that in a game but you're processing on every update within a state since the state may know how that should work. JAKE: Yeah. I’m curious – I haven’t used state machines; I’ve only used the main games. I would be interested in you guys to give us some examples on where you’ve implemented a state machine in a non-game context. That’d be interesting to me. ANDREW: Yeah, I can think of one off of the top of my head. A lot of times if you have a – a command line app is actually a good example but a command line app that takes text inputs, and say a user types a command and then you prompt them and then you want more information and then they enter another command. You want to structure your program so that it knows how to take that input and process it in a way that makes sense. And it needs to know whether a particular command is valid in the current state or not. If you’re at the top level menu then there’s a certain list of commands or states that can be entered and then each commands may have subcommands which essentially are further sub-states. So that’s a place where I’ve used state machines. You can think of similar places like that where you’ve got a user going through a branching hierarchy of interaction. CHUCK: Yeah, I’ve also done account management this way where it’s in an active state or a cancelled state or a lead state or a prospect state in marketing apps. So they just move through a progression there and they can move forward or back depending on where you’re negotiating, how you’re negotiating, what you’ve sent them, how come they did – they are and things like that. So you can get all kinds of complicated with that up to including scoring them on different areas and as the scores change, then they change states. So I’ve seen that before. That’s mostly on web applications; they submit a form and they move it to a different state. Just stuff like that. ANDREW: I think there are also places you can use state machines that a lot of people don’t use them but you can even use them just in normal application logic. If you're writing networking code and you need to be able to handle errors and retry and stuff like that, a lot of those systems can be modeled with state machines. Formalizing them as state machines can sometimes help eliminate bugs because in some sense all programming is handling various states and how to transition between them when a lot of bugs come from the program being in some state that is unexpected, and then you try to do something but it doesn’t actually work in that state, right? If you’ve formalized the states and what it means to transition between them, which transition is valid you can prevent some of those bugs. JAKE: That makes sense. So the min-max strategy stuff, I know what it’s for but I don’t completely understand what it is. It’s used in artificial intelligence but I don’t have a full understanding; I can’t really explain that one very well. CHUCK: Well maybe we’ll find an AI expert that we can bring on and have them explain that. JAKE:**I can talk a little bit about path finding but if we’re not ready [crosstalk].**ANDREW: Well, there’s path finding; the other thing that Gameplay has that we’ve talked about is the rule system stuff. I think that would be interesting. I don’t know how much you know about that but it looks like there’s this whole API for creating rule systems for your games. JAKE: I actually am – unfortunately, I don’t know much about that. That’s what I want to have and won't get yet either. ANDREW: Aww, too bad. JAKE: Yeah. Sorry about that. ANDREW:**The word ‘fuzzy logic’ is used in this. [Laughter]**JAKE: I know. I just realized – I’m looking at the docs as you're saying it and I’m like, “Is this something related at something I do know.” I haven’t looked at the API but maybe I’d know the underlying – but I don’t. It sounds awesome though. Anytime there’s fuzzy logic involved that sounds really exciting. ANDREW: Well, read up and we’ll have you back on to talk about it or something. JAKE: Yeah. CHUCK: Yeah, but let’s talk about pathfindings and sets – familiar territory. JAKE: Yeah, so I mentioned there’s an A* implementation – A*’s a form of pathfinding. So pathfinding is a way to algorithmically cause – if you think about a game like World of Warcraft – not World of Warcraft but just Warcraft like Warcraft 3 – when you send out units and they’ve got units and the units have to walk around obstacles and they have to, if there’s two sets of collections of players and they have to weave through each other, that’s pathfinding. So there’s ways where you’re trying to – and A* is an efficient algorithm to say – for example, if you’ve got an enemy player in Zelda – Legend of Zelda and then you’ve got your main player Link and how does the enemy get from where he is to seek Link but avoid obstacles n hi way. What’s the most efficient path between where he is and where Link is based on obstacles – that’s pathfinding. And so the A* pathfinding algorithm basically, you break the game world into a grid and then you basically assign each grid of value that says how difficult it is to go through that square. And so if you’ve got an obstacle, it’s a really high, infinite level of difficulty because you can’t go through it. Gauntlet’s another good example where you’ve got walls and an enemy’s got to figure out how to walk through a maze and get to you. So you assign values to each place in the grid and then the A* algorithm goes through and it adds up every possible way of getting from point A to point B and it picks the cheapest one. And you can assign higher values to walking through quicksand or things like that where it’s not impenetrable but it slows the enemy or the character down. So that’s how A* works and that’s the idea of pathfinding and so the GKGraph and the GKGraphNode are the replay GameplayKit’s method for building pathfinding algorithms. Does that make sense? CHUCK: Yeah, so you build your own graph with GraphNode and then you make those assignments inside of the GraphNode. JAKE: Yeah. CHUCK:**And do you subclass GraphNode in order to get quicksand or [inaudible].**ANDREW: Um, I am not sure about that. CHUCK: Okay. Fair enough. JAKE: There’s a fine path from node to node method. Anyway, yeah, I’ve worked with some of these APIs; I just have a generic sense what they're for because I’ve solved the problems they solved without the help of these API. CHUCK:**Hm. But yeah, when I was in college, we had to build Tank: Capture the Flag game. Right, I get a lot of these stuff – you can’t get through a wall. We had to learn all kinds of different algorithms and I remember doing [inaudible] some other and this and that.**JAKE: Yeah, there are ways to make it – you can imply it to get that immediate thing that you think of when you think of pathfinding is the top down square based levels but you can apply the same logic to a platformer where the enemy has different ways off jumping on different platforms to get from where it is to where you are. You can still cut it into a grid and say the cost of jumping from here to here is infinite because the enemy can’t jump that high and so that’s not a valid path. So you can use it in more than just the obvious ways to create AI. CHUCK: I never thought of that but that makes sense. ANDREW: I would just say that’s interesting; I’m reading about this pathfinding API and game kit, one thing that I think is, if interesting, it’s sort of different that some of the other APIs that we’ve talked about in GameplayKit is that it’s actually not very abstract. It’s more like you actually do have shapes and positions on a board and all that. There’s a class called GKObstacle and there’s a GKPolygonObstacle. So it really is concerned with the geometry of your game and I wonder, it seems like it’s designed for 2D movement, and if you're doing 3D pathfinding, I’m guessing that really complicated things unless the 3D movement is too deep. Imagine a game where you fly in 3D; do you know anything about that, Jake? Is that something you can do with GameplayKit or is that a way harder problem? JAKE:**That is a good question. I don’t know. Logically adding a third dimension, it makes it more complicated to think about it but mathematically, usually it’s the same principles apply. But whether or not the GKGraphNode can be used in 3d – I don’t know. It wouldn’t surprise me if the answer was yes or no. [Chuckles]**CHUCK:**Looking at the API, it looks like there’s a way to actually assign connected nodes. And so conceivably if you were flying, you could add a node that is the mountain and obviously that is way super high even if you're flying. But if you go up to two nodes upward then it becomes – you can fly over the mountain or it looks like you could just [crosstalk] – you could just say these are connected so you can have multidimensional connected nodes and then you just got to be smart enough to figure out that that node means you're moving higher in elevation as well as across the map.**JAKE: Yeah, that’s my read to is that base class GKGraphNode is abstract enough to handle a variety of things but then there’s also a 2D subclass of that for specifically the examples. But it does look like as long as you can break your logic in 3D space into a series of connected nodes, you should be able to use these algorithms to solve those same kind of problems. CHUCK: Yeah, and I’ve also seen games that they have that 3D element but essentially it’s just three planes and then it’s running out whether and when you can move to the other plane. JAKE: Yeah, a lot of games they're rendered in 3D but if you look at them you're like, “Really, this is it?” All the logic happens in two dimensions. CHUCK: And then moving from one plane to another is just a different rules set. JAKE: Yeah. Do you want to talk about goals and behaviors? CHUCK: Yeah, I think this can get interesting. JAKE: So there’s another set of classes, the GKAgent and GKGoal. Some examples of this are having a set off enemies chase a player around. What is that called – steering behaviors? For having some enemies flee from other enemies. These are the problems faced by GKAgent and GKGoals. CHUCK: Oh okay. I was thinking more of in the lines of – again if you’re playing that Capture the Flag or something in your drive or in your cart the goal would be the flag. But it sounds like that’s not the case; it’s something else. JAKE: Yeah. CHUCK: This is the AIs in your system and providing behaviors to them. JAKE: Yeah, a couple of examples from the API is goal to seek agent, goal to flee agent, goal to reach target, goal to wanderer, right? CHUCK: Uh-hm. JAKE: That’s part of the GKGoal class which you can also do on the GKAgent you can define acceleration and speed, and so you say ‘I want this agent to seek this agent at this speed’ that you just let it go and it will do it. Does that make sense? So that logic is not super hard to implement but it’s way easier if you can just say ‘I want this thing to chase after this thing and this is its max speed’. CHUCK: Uh-hm. Yeah, that makes a lot of sense because then you don’t have to solve that yourself; you just – you can define it in general and common terms and you don’t have to build the abstraction yourself. ANDREW: Right, and I’m wondering if you say ‘I want this thing to chase this thing but to flee from this thing at the same time’, you just kind of let it go and see what happens but I’m not sure – yeah, the agent value is GKGoal object list it’s behavior proper so you can have more than one. CHUCK: Hm. That’s interesting. So it has a radius on it as well so I’m assuming that then if your goal – so let’s say you’re one AI is slightly slower than the other AI or player, and so once the player gets a way, gets outside that radius then it stops evaluating it. JAKE: It’s also to avoid actually overlapping too much, so if you wanted to give a float space where you're like ‘I don’t ever actually want this to touch’, you can use radius for that. CHUCK: Okay. JAKE: So. CHUCK: Huh. So one thing I’m seeing here too is that this all says tvOS on it. ANDREW: You're just looking at the wrong link but it’s an iOS framework. TvOS is essentially iOS. CHUCK: Right. ANDREW: And it’s actually available on OS 10 as well. CHUCK: Yeah, I found I’ve read that somewhere but then I –. ANDREW: Apple’s been doing a good job the last few years of making it so these frameworks that are sort of – I don’t know what you’d called them – they're not UI kit or app kit; these frameworks that are separate from the actual UI conventions of the platform are on both OS 10 and iOS, and of course now that tvOS is a thing and WatchOS to some degree. They're all on there, too. Especially for games; they’ve been thinking from the beginning that you can make a game that will work on both OS 10 and iOS and now tvOS without having to rewrite the whole thing which is nice. CHUCK: Yeah. So I guess the other thing that I’m wondering about – and you brought this up earlier, Jake – is does GameplayKit work with Unity or some of these other systems? Or is this kind of a different system altogether? JAKE: It works in the context of Objective-C or Swift Code. So Unity is a container system; now you could build a plugin for Unity that relied on game kit and then expose – GameplayKit and then expose some of GameplayKit stuff to Unity but they're two different environments. In order to use GameplayKit in Unity you’d need to write that plugin. But yeah, anywhere you have access to Apple’s code – framework level code, you could use it. Does that answer your question? CHUCK: Uh-hm. JAKE: I can say that the source examples that come with – that are in the documentation are quite food and they do a great job of covering a lot of the different classes and options you have available. And so if you're interested in the best way to jump into it, at least right now, is to read the docs and then start looking at it, planning with the sample code because there’s three, four different projects and they're all pretty significant. When SpriteKit first came out, they gave us a huge sample project for that. For whatever reason, the sample projects have come with game frameworks from Apple are much more fully developed than a lot of the sample code we get with AV Foundation or whatever. ANDREW: Yeah, that’s been pretty nice, right? It must be the overall team that works on the game APIs for Apple’s platforms is just – it’s embedded in the team that they're going to produce really good sample code. JAKE: Yeah, and in fact with the first SpriteKit game that we brought in, a game designer – I can’t remember his name right now but he’s a really well known game designer to build the game that they then produced a sample code for. ANDREW:**I wanted to talk to you about not really specifically with GameplayKit but all of these game frameworks that are on iOS now. It seems to me one of the big problems with using them is they limit you to being on Apple’s platforms. You can’t be cross-platformed if you use them. Games – otherwise, in contrast with regular apps games, typically lend themselves really well to being cross-platformed. Because they take over the whole screen, they define their own UI conventions. They don’t need to match platforms UI conventions. They typically don’t do anything that is really specific to a particular platform. They implement all of their own logic and graphics and all that, and for that reason a lot of games seem like they are cross-platformed and I wonder if you think that these frameworks are really seeing very wide options among serious game developers or they're basically just being used by the biggest [inaudible] people. Or maybe [inaudible].**JAKE:**Yeah – no. I can tell you what I do know which doesn’t fully answer your question but if you go to – I go to the local independent gaming club from time to time and when I go there, 90% of those people are in Unity. A lot of them are targeting iOS but they also want to target Android, they also want to target – even though [inaudible] our primary looking at building an iOS game first, they are using Unity and that could be a lot of different reasons. Obviously, the access to Unity in easier because you don’t have to have a Mac; you don’t – any system that you have you can run Unity on. And Unity is – also from a developer’s point of view – from a game designer’s point of view, Unity’s easier to get stuff going. The interactive editor in Unity is really robust so you can visually drop elements in [inaudible] and then hit run and then it starts running and you can edit the game using the same editor as you play it, as you used to build it. So Apple’s tools like the SceneKit – the SceneKit editor which will edit collada files and the SpriteKit editor which will edit SKScene files. These tools are good and every year they give us more of these tools, but they're still several steps behind. Unity’s my primary example but there are other tools out there that are similar to Unity. I’m just familiar with Unity. So from the perspective of ‘if I want to be a game designer and I want to get into games; where should I go?’ it seems like usually the answer to that is Unity but when I do see people using SpriteKit and SceneKit – people like us, Cocoa developers who are interested in doing games. And I’m sure that there are examples of great games on the app store that use those tools but it does seem like people that are focused primarily on games and get into programming space from the perspective of wanting to make games, these days it seems like Unity is more appealing to these group of people. That’s my impression. I would love to hear from other people if they’ve got some counter examples.**ANDREW:**That’s the impression that I got, too. I just – as an interesting point of history, Unity was originally an OS 10 only thing. I can’t remember what platforms they allowed you to deploy, too, at first but the tools themselves were Mac only when they first came out. And in fact they were announced that WWDC which is crazy. [Chuckles]**CHUCK: Cool. JAKE:**That is interesting. I got into iOS programming thinking that I wanted to do games but at that time, Unity was much less developed and way more expensive. And Cocoa [inaudible] was kind off the forefront. If you want to make games on iOS, you look at Cocoa [inaudible] first and then I learned SpriteKit and then I learned SceneKit. I came out from a different angle and I think there’s other – lot of people like me who have come to that same path. But it does seem like these days new people who are just coming into the space are looking at Unity.**ANDREW: I’d be kind of interested for somebody to take the top two – I saw a blog post recently where somebody downloaded the top 100 apps on the app store and then they looked through the binary to figure out which libraries the apps were using and then they compiled some statistics to figure out the most popular third party libraries in the top 100. IOS app’s on the store but it’d be interesting to have somebody do that with games and then figure out which technology they are using for – which game engineer they're using. JAKE: Yeah. I thought that same thing. I would love to know – if you just look at the top 100 games, what are people using because then they're also just people not writing their own engine. They're not using any prebuilt engine at all. And I’m guessing some of the bigger studios, that’s what they're doing. ANDREW: Yeah, so bigger studios are right there on engines but I think even some of the bigger studios used like Unity or Unreal Engine. CHUCK: Alright. I think we’re winding down; shall we get to the picks? ANDREW: Sounds good. JAKE: Yup. CHUCK: Alright Andrew, what are your picks? ANDREW:**I have three picks today, and to make up for last week, they're all iOS development related; they're not just fluffy stuff. My first pick is a set of tools called Fastlane. I was talking to Chuck a little bit about them before the show started and they're pretty well-known now but they're just these bunch of iOS tools for automating common ion development tasks including building your projects, testing your projects, downloading provisioning profiles, fixing code signing, uploading to iTunes Connect for test flight in the app store. They can also upload some other beta testing services. There’s a tool that’s part of the suite that will automatically take screenshots of your app which is pretty nice because you just run the tool and it uses the UI testing automation stuff to bring up your app, take a screenshot of all the things you want to take and every single language you support on every device that you support and upload all that metadata to iTunes Connect. Pretty cool stuff and it all – you can all integrate it with a built server like Jenkins or something. That’s Fastlane. The next thing is a three part blog post. I don’t think I actually know what this guy’s name is but anyway, he has a series of blog post on Swift state machines and it kind of goes along with what we’re talking about state machines; he’s not talking about games at all, he’s actually showing you how state machines can be used to implement normal app logic in particular, some networking stuff. And he has some real Swift code that uses features that are particularly Swift to do this in a pretty nice way. So that’s my second pick and my third pick is this thing that I just mentioned. This post – it’s by Ryan Olsen where he downloaded the top 100 apps and then did some analyses of them and looked at how many classes are in [inaudible] and which libraries they are using. It’s pretty interesting the fact that Facebook’s apps and Google’s apps have the most number of classes. I think it was Facebook; he doesn’t actually say it, he hints at it but Facebook had the most number of Objective-C classes and had 15 times the median so it was like almost 20,000 classes which is crazy. And the top library was the Facebook STK which is also not surprising but anyway that was an interesting post. Those are my picks.**CHUCK: Alright, I’ve got a couple of picks here. The first one is I’ve had this standing desk for a while just sitting in my office probably a few years. I built it; it’s the Lifehacker Ikea standing desk. I’ll put a link to that on the show notes. But anyway, I did a quick Periscope which I should also pick on the show – I think I might have picked it before – showing how I have it set up. I just barely moved everything over to it including my recording set up. And the idea is that I want to basically do all of my conference calls, mastermind groups and podcasts standing instead of sitting. What that means is that Tuesdays and Wednesdays are long days but anyway, I put all these together so you can go check it out. I’ve been doing a Periscope about every weekday and so I’ll put a link to that as well. I’m calling the series upgrading from yesterday and the idea is I’m talking about how I’m doing better each day than the day before. I am also planning on doing some online conferences and there’s an episode on that as well. It’s episode number six and if you look at the list, you’ll see that I’m actually planning on doing a Remote conference for iOS in April. So if you're interested in that, keep an eye out for it and I’ll put more information up when I have it. Yeah, so I also pick Periscope. I’m really, really liking Periscope. And if you don’t know what it is, I’ll just give you a brief overview. It is a program; it’s actually owned by twitter now. And what you do is you get it on your phone and – you can actually follow me. My Periscope handle is the same as my Twitter handle. Makes sense because Twitter owns it. But what it does is it allows you to live broadcast from your phone. Mine have been anywhere from six to twenty minutes just depending on what I was talking about. Anyway, people can actually sign on and watch. If you tap the screen then it gives them hearts so if you're really like what you’re seeing, you’re hearing, then you can do that. Then you can also send chat messages and the person doing the Periscope can see those and reply and I usually try and reply if I recognize somebody coming on, or somebody says something you know of stuff and say something about it. So if you're interested in that, you can go check it out. Periscope app is available on Android and iOS. So yeah, go check all that stuff out. I’m really, really enjoying Periscope and I’m enjoying the interaction that I get with folks. Anyway, those are my picks. Jake, what are your picks? JAKE: So I’m going to pick the sample code for the GameplayKit. If you're interested in GameplayKit, the sample code is an awesome resource to learn more about it, just how to use it. I also am going to pick the iOS Games by Tutorials by Ray Wenderlich. Now, normally that would be very self-serving but I am not actually participating this year. So I was on it last year but the new one that’s going to come out – October 28th which may – I’m not sure exactly when this recording will be released but it’ll be close, I assume, to October 28th. That’s when the new iOS Games by Tutorials are going to come out. And the great thing about Ray is that he always uses the latest and greatest code strategies and technologies so the entire book will use GameplayKit where appropriate for – it’s primarily on SpriteKit but GameplayKit’s going to be throughout the book. So again, if you're interested in that I think that’ll be a great resource. And then the last thing I’m going to pick is this book called The Life-Changing Magic of Tidying Up by Marie Kondo. My wife read this book; I read parts of it. It’s not a great read but the basic idea is that you go through everything you own and you throw most of it away. The only stuff you keep is the stuff that really makes you happy. So my wife has been on this campaign to clean up our house and you would be surprised at how great you feel when you look, you go into a closet and instead of having a pile of junk in there, the only stuff that’s left is stuff that you actually value. Even though the book’s kind of – it’s just hard to relate to the perspective of other person because she talks about how, as a teenager, she spend all day cleaning her room and I was like ‘I don’t get this person’, but the impact of her principles I really enjoyed a cleaner, nicer place to live. You either read it or have your wife read it. ANDREW:**Jake, I’ve been to your house and I’ve always thought it was exceptionally uncluttered. [Laughter] Nott really sure you guys needed that book.**JAKE: Yeah, the thing is that we don’t have piles of stuff everywhere but if you go into our – we have moved more times than years we have been married, me and my wife. And every time we move there is like boxes and boxes of stuff that we don’t ever unpack, that we just move. ANDREW:You can write a book about that [laughter] as a scheme, right?JAKE: Yeah, so we’re not super cluterry to begin with but we went through a bookshelf full of books and we got rid of probably 80% of those books because we’re not going to read them. And now when I look at that bookshelf, what’s there is only stuff that I’m happy to see on that shelf. It’s a really interesting point of view. Anyway, that’s my last pick. CHUCK: Awesome. Well if people want to follow up with you, follow you on Twitter, just see what you’re about where do they go Jake? JAKE: So it’s @fattjake with two t’s. It’s hard to remember because there’s two t’s in it but it’s @fattjake with two t’s on Twitter. That’s the best place to find me. CHUCK: Fat spelled like Jabba the Hutt with two t’s. JAKE: Yup. CHUCK: Alright, well we’ll go ahead and wrap up the show. Thanks for coming, Jake! This was a lot of fun. JAKE: Yeah, thanks. I was happy to be here. CHUCK: Yeah, and we’ll catch everyone next week. [Hosting and bandwidth provided by the Blue Box Group. Check them out at BlueBox.net.]**[Bandwidth for this segment is provided by CacheFly, the world’s fastest CDN. Deliver your content fast with CacheFly. Visit cachefly.com to learn more]**[Would you like to join a conversation with the iPhreaks and their guests? Want to support the show? We have a forum that allows you to join the conversation and support the show at the same time. You can sign up at iphreaksshow.com/forum]**

Sign up for the Newsletter

Join our newsletter and get updates in your inbox. We won’t spam you and we respect your privacy.