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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.