Geometrical primitives

When developing games, you will usually work with high-level elements, such as sprites, labels, particle systems, or physical bodies. But sometimes you will need to create simple shapes, such as circles, lines, rectangles. For example, you may need to do so to create a prototype for your next game.

SpriteKit provides us with a subclass of SKNode named SKShapeNode, which doesn't have much potential. This class allows us to create rectangles (init(rect:), init(rectOfSize:), init(rect:cornerRadius:), and init(rectOfSize:cornerRadius:)), ellipses (init(ellipseOfSize:) and init(ellipseInRect)), circles (init(circleOfRadius:)), and other types of shape by providing its vertices (init(points:count:)) or path (init(path:centered:) ...

Get Getting Started with SpriteKit now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.