Instance Method

initWithColor:size:

Initializes a colored sprite node.

Declaration

iOS, Mac Catalyst, tvOS, watchOS
- (instancetype)initWithColor:(UIColor *)color size:(CGSize)size;
macOS
- (instancetype)initWithColor:(NSColor *)color size:(CGSize)size;

Parameters

color

The color for the resulting sprite node.

size

The size of the sprite node in points.

Return Value

A newly initialized sprite node.

Discussion

Although textured nodes are the most common way to use the SKSpriteNode class, you can also create sprite nodes without a texture. The behavior of the class changes when the node lacks a texture:

  • The sprite node that is returned from this method has its texture property set to nil.

  • There is no texture to stretch, so the centerRect parameter is ignored.

  • There is no colorization step; the color property is used as the sprite’s color.

  • The sprite node's alpha component is used to determine how it is blended into the buffer.

See Also