Class

GKPolygonObstacle

A polygon-shaped impassable area in a 2D game world.

Declaration

@interface GKPolygonObstacle : GKObstacle

Overview

Polygon obstacles serve two purposes in GameplayKit: You can use polygon obstacles to construct a navigability graph of your game world (a GKObstacleGraph object) for use in pathfinding. You can also use polygon obstacles to define regions for agents (GKAgent objects) to avoid, using the GKGoal method goalToAvoidObstacles:maxPredictionTime:.

To easily create obstacles for use with a SpriteKit game, create and arrange a set of nodes that define the non-navigable regions of your game world. You can create such nodes programmatically, or use the SpriteKit Scene Editor in Xcode. If you’re already using nodes with physics bodies to keep sprites from entering those regions, you can reuse those nodes. Then, use the obstaclesFromNodeBounds:, obstaclesFromSpriteTextures:accuracy:, or obstaclesFromNodePhysicsBodies: method to generate a set of GKPolygonObstacle objects.

To learn more about both ways of using polygon obstacles, see Pathfinding and Agents, Goals, and Behaviors in GameplayKit Programming Guide.

Topics

Creating a Polygon Obstacle

- initWithPoints:count:

Initializes a polygon obstacle with the specified list of vertices.

+ obstacleWithPoints:count:

Creates a polygon obstacle with the specified list of vertices.

Inspecting Vertices

vertexCount

The number of vertices that define the polygon-shaped area of the obstacle.

- vertexAtIndex:

Returns the point coordinates of the specified vertex.

Relationships

Inherits From

Conforms To

See Also

Obstacles

GKObstacle

The abstract base class for objects representing impassable areas in a game world.

GKCircleObstacle

A circular impassable area to be avoided by agents.

GKSphereObstacle

A spherical impassable volume to be avoided by agents.