

I quickly found myself building extension to support conversion between these and more common Core Graphics structs.
#Wwdc 2015 video update#
Agents update directly ( myAgent.updateWithDeltaTime(dTime)) or use a coordinator ( GKComponentSystem) that synchronously dispatches updates to all its children.Īt least in its initial release, GameplayKit classes use simd structs to represent most vector values. You can tie that clock to a SpriteKit update: method, to an NSTimer, to a CADisplayLink firing, or even run a for-loop iteratively without any real-world analogy to the "time". You advance it only when and how you see fit. The higher a goal is weighed, the more it affects the engine's choice of outcomes. A single agent might seek some goal (at, say 60%) while avoiding other agents (at 40%), for example. Although this example uses just one behavior, you can assign several behaviors to any agent at a single time. When the agent has reached its goal, I move the target and reset the behavior. Let d = Distance(myAgent.cgPosition, targetAgent.cgPosition) Each time the "hero" agent updates its state, I can test whether the goal has succeeded: This snippet creates and assigns a seeking behavior that targets another agent. Let behavior = GKBehavior(goal: goal, weight: 1) Let goal = GKGoal(toSeekAgent: targetAgent)
#Wwdc 2015 video code#
Here's what the core code looks like for this demonstration. GameplayKit handles all of this on your behalf.

It feels much more natural than turning on a dime. Its velocity vectors must decelerate, rotate, and re-target. The agent doesn't just stop and change directions when the target updates. The following video demonstrates a simple seeker that tracks down a randomly moving target. Presets include wandering, fleeing, seeking, flocking (called cohering), following paths, and obstacle avoidance. Let GameplayKit handle the details of how those agents achieve their goals. Just establish a working model and create the agents that inhabit it. It enables you sidestep recreating common patterns each time you start a project. Whether you're shuffling a deck of cards or creating a flock of enemy robots hunting down your hero, the framework minimizes overhead and lets you focus more on your unique story. The underlying goal of GameplayKit is to create systems that abstract away repetitive details common to gaming development. Of course, if you're only focused on "how can this work in traditional interfaces," you'll miss out on many great features that are specifically designed to enhance gameplay. When adding a button to a display, why not have the other labels and text fields use a "flee pattern" to make room for the new element, for example? They can introduce liveliness to dialogs, forms, and other UI elements. The fun agent-based updates can easily be used in any interface. Like UIKit's dynamic view animations, these APIs don't just support gaming. You can tie the semantics it generates into SpriteKit and SceneKit visualizations or even to UIKit layouts however you wish. It provides no UI specifics or physicality apart from the numbers that drive its model. GameplayKit lives entirely in the model world of model-view-controller. The latter builds smart goal-oriented agents that optimize their behaviors in constrained environments. The former enables you to create state machines and min-max-optimized strategies.

These are split fairly evenly between game-logic support and autonomous agent gaming. The GameplayKit framework consists of sixteen classes. GameplayKit joins SpriteKit, SceneKit, and Metal, an evolving suite that's marked by Apple-sourced APIs deployed to Apple-specific destinations. It is part of Apple's ongoing work to consolidate gaming under a native framework umbrella. Gourmet iOS Developer's Cookbook, The: Even More Recipes for Better iOS App DevelopmentĪpple's new GameplayKit framework debuted at WWDC 2015.
