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:)
).
In this section, we are going to take advantage of this class in order to create a life bar, which will consist of a red rectangle in the background and a green rectangle in the foreground. This life bar will represent the main character's life points...