SKUShapeNode
IntroductionApple'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. GroupsInitializationGroup members:
Methods
circleWithRadius:andColor:circleWithRadius:andColor:circleWithRadius:andColor: +(SKUShapeNode*)circleWithRadius:(CGFloat)radius andColor:(SKColor*)color NS_SWIFT_NAME(init( circleWithRadius:andColor:)); ParametersReturn ValueSKUShapeNode DiscussionConvenience 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:)); ParametersReturn ValueSKUShapeNode DiscussionConvenience 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:)); ParametersReturn ValueSKUShapeNode DiscussionConvenience 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:)); ParametersReturn ValueSKUShapeNode DiscussionConvenience 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:)); ParametersReturn ValueSKUShapeNode DiscussionConvenience method that creates and returns a new shape object in the shape of a sqaure. Properties
anchorPoint@property (nonatomic, assign) CGPoint anchorPoint; DiscussionAnchor point of the sprite. antiAlias@property (nonatomic, assign) BOOL antiAlias; DiscussionBoolean determining whether to anti-alias the rendered image. fillColor@property (nonatomic, retain) SKColor *fillColor; DiscussionThe color to fill the path with. Defaults to [SKColor clearColor] (no fill). fillRule@property (nonatomic, assign) NSString* fillRule; DiscussionThe fill rule used when filling the path. Options are `non-zero' and `even-odd'. Defaults to `non-zero'. lineCap@property (nonatomic, assign) NSString* lineCap; DiscussionSee CAShapeLayer for information on this. lineDashPattern@property (nonatomic, assign) NSArray* lineDashPattern; DiscussionCausing 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; DiscussionCausing 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; DiscussionSee CAShapeLayer for information. lineWidth@property (nonatomic) CGFloat lineWidth; DiscussionThe 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; DiscussionMiter limit value for stroked paths. path@property (nonatomic) CGPathRef path; DiscussionThe 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; DiscussionThe color to draw the path with. (for no stroke use [SKColor clearColor]). Defaults to [SKColor whiteColor]. texture@property(nonatomic, readonly) SKTexture* texture; DiscussionReadonly access to the rendered texture. MIGHT not be properly retina-ized. |