SKCropNode fails when I add extra SKNode children in hierarchy

Update: It looks like iOS 10 has fixed this issue. I upgraded to Swift 3 and Xcode 8 and everything is working as expected.


I’ve run into this issue a couple times now and I can’t tell if it’s a bug in SKCropNode or if I’m just misusing it. Perhaps there’s some bit of documentation I’m missing to explain why this is happening?

  • how to identifying Iphone incoming call and display notification?
  • Warning: UICollectionViewFlowLayout has cached frame mismatch for index path 'abc'
  • Is there a sqlite .dump equivalent in objective-c?
  • Xcode “valid signing identity not found” on new Computer
  • iOS Facebook SDK 3.1 Retrieve friend birthday returning null
  • How do I create a custom struct to assign the contents of array into usable variables?

  • I have a crop node with a 100×100 rectangle shape as the mask. If I place a blue circle inside it, it gets cropped properly.

    // Create a crope node with a small square.
    let cropNode = SKCropNode()
    let cropNodeMask = SKShapeNode(rect: CGRect(x: 0, y: 0, width: 100, height: 100))
    cropNodeMask.fillColor = UIColor.whiteColor()
    cropNode.maskNode = cropNodeMask
    self.addChild(cropNode)
    
    // Create a blue circle and put it in the crop node.
    let blueCircle = SKShapeNode(circleOfRadius: 110)
    blueCircle.fillColor = UIColor.blueColor()
    blueCircle.strokeColor = UIColor.clearColor()
    cropNode.addChild(blueCircle)
    

    enter image description here


    Now, when I place that same circle inside of an otherwise empty SKNode and place that container inside the same crop node, cropping fails.

    // Create a crope node with a small square.
    let cropNode = SKCropNode()
    let cropNodeMask = SKShapeNode(rect: CGRect(x: 0, y: 0, width: 100, height: 100))
    cropNodeMask.fillColor = UIColor.whiteColor()
    cropNode.maskNode = cropNodeMask
    self.addChild(cropNode)
    
    // Create a container to hold the circle.
    let container = SKNode()
    cropNode.addChild(container)
    
    // Create a blue circle and put it in the container.
    let blueCircle = SKShapeNode(circleOfRadius: 110)
    blueCircle.fillColor = UIColor.blueColor()
    blueCircle.strokeColor = UIColor.clearColor()
    container.addChild(blueCircle)
    

    enter image description here


    But a sprite in that same container seems to be cropped fine.

    // Create a crope node with a small square.
    let cropNode = SKCropNode()
    let cropNodeMask = SKShapeNode(rect: CGRect(x: 0, y: 0, width: 100, height: 100))
    cropNodeMask.fillColor = UIColor.whiteColor()
    cropNode.maskNode = cropNodeMask
    self.addChild(cropNode)
    
    // Create a container to hold the sprite.
    let container = SKNode()
    cropNode.addChild(container)
    
    // Create a spaceship and add it to the container.
    let spaceshipNode = SKSpriteNode(imageNamed: "Spaceship")
    spaceshipNode.anchorPoint = CGPointZero
    container.addChild(spaceshipNode)
    

    enter image description here

    Solutions Collect From Internet About “SKCropNode fails when I add extra SKNode children in hierarchy”

    SKShapeNode is bugged, best to avoid it at all costs. Use it to create your shapes, then convert it to a texture for use with SKSpriteNode