SKUShapeNode

Conforms to:
NSCopying
Superclass:
SKNode
Declared In:

Introduction

Apple's shape generator for SpriteKit causes performance issues. Shapes are rerendered each frame, despite a lack of change in appearance. You can cheat by parenting it to an SKEffectNode and setting it to rasterize. However, any changes cause it to rerender with high cpu usage. It also has low quality anti aliasing. Instead, you can use this class. SKUShapeNode uses CAShapeLayer to render a shape, which is slightly more costly than the rendering of the SKShapeNode, but once it's rendered, is cached as a bitmap and renders very quickly in SpriteKit thereafter. TLDR: SpriteKit's shape node fast redner, slow draw. SKUShapeNode is slow render, fast draw.



Groups

Initialization

Group members:


Methods

+circleWithRadius:andColor:circleWithRadius:andColor:

circleWithRadius:andColor:

+rectangleRoundedWithSize:andCornerRadius:andColor:rectangleRoundedWithSize:andCornerRadius:andColor:

rectangleRoundedWithSize:andCornerRadius:andColor:

+rectangleWithSize:andColor:rectangleWithSize:andColor:

rectangleWithSize:andColor:

+shapeWithPath:andColor:shapeWithPath:andColor:

shapeWithPath:andColor:

+squareWithWidth:andColor:squareWithWidth:andColor:

squareWithWidth:andColor:


circleWithRadius:andColor:circleWithRadius:andColor:


circleWithRadius:andColor:

+(SKUShapeNode*)circleWithRadius:(CGFloat)radius andColor:(SKColor*)color NS_SWIFT_NAME(init(
                circleWithRadius:andColor:)); 
Parameters
radius

radius of circle.

color

Color of circle.

Return Value

SKUShapeNode

Discussion

Convenience method that creates and returns a new shape object in the shape of a circle.


rectangleRoundedWithSize:andCornerRadius:andColor:rectangleRoundedWithSize:andCornerRadius:andColor:


rectangleRoundedWithSize:andCornerRadius:andColor:

+(SKUShapeNode*)rectangleRoundedWithSize:(CGSize)size 
        andCornerRadius:(CGFloat)radius andColor:(SKColor*)color NS_SWIFT_NAME(init(
                rectangleRoundedWithSize:andCornerRadius:andColor:)); 
Parameters
size

CGSize value to make a rectangle of.

radius

Radius value for corners

color

Color of shape

Return Value

SKUShapeNode

Discussion

Convenience method that creates and returns a new shape object in the shape of a rounded rectangle.


rectangleWithSize:andColor:rectangleWithSize:andColor:


rectangleWithSize:andColor:

+(SKUShapeNode*)rectangleWithSize:(CGSize)size andColor:(SKColor*)color NS_SWIFT_NAME(init(
                rectangleWithSize:andColor:)); 
Parameters
size

CGSize value to make a rectange of.

color

Color of rectangle.

Return Value

SKUShapeNode

Discussion

Convenience method that creates and returns a new shape object in the shape of a rectanlge.


shapeWithPath:andColor:shapeWithPath:andColor:


shapeWithPath:andColor:

+(SKUShapeNode*)shapeWithPath:(CGPathRef)path andColor:(SKColor*)color NS_SWIFT_NAME(init(
                shapeWithPath:andColor:)); 
Parameters
path

CGPathRef path to make a shape out of. A copy is made, so you are responsible for releasing this reference.

color

Color to make shape.

Return Value

SKUShapeNode

Discussion

Convenience method that creates and returns a new shape object in the shape of the provided path.


squareWithWidth:andColor:squareWithWidth:andColor:


squareWithWidth:andColor:

+(SKUShapeNode*)squareWithWidth:(CGFloat)width andColor:(SKColor*)color NS_SWIFT_NAME(init(
                squareWithWidth:andColor:)); 
Parameters
width

Value that determines size of square.

color

Color of square

Return Value

SKUShapeNode

Discussion

Convenience method that creates and returns a new shape object in the shape of a sqaure.


Properties

anchorPoint
antiAlias
fillColor
fillRule
lineCap
lineDashPattern
lineDashPhase
lineJoin
lineWidth
miterLimit
path
strokeColor
texture

anchorPoint


@property (nonatomic,
    assign) CGPoint anchorPoint; 
Discussion

Anchor point of the sprite.


antiAlias


@property (nonatomic,
    assign) BOOL antiAlias; 
Discussion

Boolean determining whether to anti-alias the rendered image.


fillColor


@property (nonatomic,
    retain) SKColor *fillColor; 
Discussion

The color to fill the path with. Defaults to [SKColor clearColor] (no fill).


fillRule


@property (nonatomic,
    assign) NSString* fillRule; 
Discussion

The fill rule used when filling the path. Options are `non-zero' and `even-odd'. Defaults to `non-zero'.


lineCap


@property (nonatomic,
    assign) NSString* lineCap; 
Discussion

See CAShapeLayer for information on this.


lineDashPattern


@property (nonatomic,
    assign) NSArray* lineDashPattern; 
Discussion

Causing exceptions (at least on OSX) - keeping it in there cuz I BELIEVE the error is on Apple's side. Careful using this though. See CAShapeLayer for information.


lineDashPhase


@property (nonatomic,
    assign) CGFloat lineDashPhase; 
Discussion

Causing exceptions (at least on OSX) - keeping it in there cuz I BELIEVE the error is on Apple's side. Careful using this though. See CAShapeLayer for information.


lineJoin


@property (nonatomic,
    assign) NSString* lineJoin; 
Discussion

See CAShapeLayer for information.


lineWidth


@property (nonatomic) CGFloat lineWidth; 
Discussion

The width used to stroke the path. Widths larger than 2.0 may result in artifacts. Defaults to 1.0.


miterLimit


@property (nonatomic,
    assign) CGFloat miterLimit; 
Discussion

Miter limit value for stroked paths.


path


@property (nonatomic) CGPathRef path; 
Discussion

The CGPath to be drawn (in the Node's coordinate space) (will only redraw the image if the path is non-nil, so it's best to set the path as the last property and save some CPU cycles)


strokeColor


@property (nonatomic,
    retain) SKColor *strokeColor; 
Discussion

The color to draw the path with. (for no stroke use [SKColor clearColor]). Defaults to [SKColor whiteColor].


texture


@property(nonatomic,
    readonly) SKTexture* texture; 
Discussion

Readonly access to the rendered texture. MIGHT not be properly retina-ized.