在我的应用中,我想在Stylekit
中实现使用PaintCode(SKScene
)制作的圆圈。
这是我的代码:
import SpriteKit
import GameplayKit
class GameScene: SKScene {
override init(size: CGSize) {
super.init(size: size)
StyleKit.drawCanvas1()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func didMove(to view: SKView) {
}
}
如何解决此问题?
答案 0 :(得分:0)
你可以用这种方式构建SKSpriteNode
:
func makeCircle(width:CGFloat = 200, height:CGFloat = 200) -> SKSpriteNode? {
let size = CGSize(width: width, height: height)
UIGraphicsBeginImageContextWithOptions(size, false, 0)
StyleKit.drawCircle(frame: CGRect(origin: .zero, size: size), resizing: .AspectFit)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
if let safeImage = image {
return SKSpriteNode(texture: SKTexture(image: safeImage))
} else {
return nil
}
}