I could use a few pointers with turning PaintCode files into SKShapeNodes for use in an app I am building. There are two specific issues I am trying to overcome, as outlined below. I am using Xcode 6 beta 4, SpriteKit, Swift and PaintCode for the project. First, the code:
import UIKit
import SpriteKit
class Ad_disclighttop : SKShapeNode {
var ovalPath: UIBezierPath = UIBezierPath()
var oval2Path: UIBezierPath = UIBezierPath()
init() {
super.init()
drawDisc()
self.name = "White Disc"
self.path = ovalPath.CGPath
}
//// Initialization
override class func load() {
}
//// Drawing Methods
func drawDisc() {
//// General Declarations
let context = UIGraphicsGetCurrentContext()
//// Color Declarations
let xFFFFFF66 = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 0.400)
let x00000066 = UIColor(red: 0.000, green: 0.000, blue: 0.000, alpha: 0.400)
//// Gradient Declarations
let markerTopGradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), [xFFFFFF66.CGColor, x00000066.CGColor], [0.01, 1])
//// MarkerW_04
//// Oval Drawing
ovalPath = UIBezierPath(ovalInRect: CGRectMake(0, 0, 60, 60))
UIColor.whiteColor().setFill()
ovalPath.fill()
x00000066.setStroke()
ovalPath.lineWidth = 1
ovalPath.stroke()
//// Oval 2 Drawing
oval2Path = UIBezierPath(ovalInRect: CGRectMake(2.5, 2.5, 57, 57))
CGContextSaveGState(context)
oval2Path.addClip()
CGContextDrawRadialGradient(context, markerTopGradient,
CGPointMake(35.87, 38.3), 20.28,
CGPointMake(23.16, 25.59), 40.36,
UInt32(kCGGradientDrawsBeforeStartLocation) | UInt32(kCGGradientDrawsAfterEndLocation))
CGContextRestoreGState(context)
}
}
@objc protocol StyleKitSettableImage {
var image: UIImage! { get set }
}
@objc protocol StyleKitSettableSelectedImage {
var selectedImage: UIImage! { get set }
}
First problem I am encountering is that almost every non-trivial PaintCode file I produce has more than one UIBezierPath in it. The SKShapeNode's path property can only take one path, as far as I know, but perhaps it is possible to chain them some how?
Second problem is that the gradient colors do not seem to work.
The things I did to actual turn this file into an SKShapeNode was to: 1. import SpriteKit 2. Change the class extension from NSObject to SKShapeNode 3. rename the drawing function 4. create an init function for the shape node that sets the name and path
I am happy to receive any tips at all on this type of conversion. Thanks!
Since gradient colors do not work anyway in SKShapNode nodes, I decided to render PNG files from within PaintCode, and I create SKSpriteNodes with them. Not the solution I was hoping for, but it is what it is.