0

I am very new to SpriteKit, and unfortunately cannot find any resources online to find out how this works. Basically, I have tried to create a diamond (from other's questions and answers on here). This is what I have:

let node = SKShapeNode()

var path:CGMutablePath = CGPathCreateMutable()
CGPathMoveToPoint(path, nil, 200, 200)
CGPathAddLineToPoint(path, nil, 250, 250)
CGPathAddLineToPoint(path, nil, 200, 300)
CGPathAddLineToPoint(path, nil, 150, 250)
CGPathAddLineToPoint(path, nil, 200, 200)
CGPathCloseSubpath(path);
node.path = path;
node.fillColor = SKColor.orangeColor()
self.addChild(node)

I have placed this code in the viewDidLoad. However, when I run this, all I get is the grey screen... Can anyone assist me? And if so, is it possible to do the same for 2/3 of a circle instead of the diamond? I would like objects to be able to enter the cirlce... Can anyone also recommend anywhere where I can learn how to create 'paths' around objects?
I've tried using the bodyWithTexture:alphaThreshold:size: on the Apple guide, but cannot figure out how this works?
Sorry for such a long question, any help would be much appreciated!

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • 1
    keep in mind that skshapenode is slow, mainly intended for debugging ie don't build all you game graphics with it, use sprites instead – CodeSmile Jan 24 '15 at 09:50
  • @LearnCocos2D thanks.. shall i just use skspritenode then? And can you recommend anywhere that teaches it please? Thanks. – Jack Whitaker Jan 24 '15 at 11:16

1 Answers1

1

Working with CGPath can be complicated sometimes, that's why people have built tools like the SKImport with an awesome editor, which creates you the objects and the CGPath which you can use in your project.

enter image description here

Link to original question

Community
  • 1
  • 1
Christian
  • 22,585
  • 9
  • 80
  • 106
  • thanks but i cannot find a way to use this in swift... it looks like Objective-C. Any other recommendations? Thanks. – Jack Whitaker Jan 24 '15 at 11:19
  • You can use Objective-C Frameworks in Swift. Check this link: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html – Christian Jan 24 '15 at 11:50