Trying to addChild withSKCropNode - Error

53 Views Asked by At

I am working on a ball game and new to swift. I am trying to make the ball two colors using SKCropeNode. It is throwing this error: "cannot invoke addchild with an argument list of type (skcropnode)"

I tried many different things but Im not sure how to fix this. Thank you for your help

    static func make()-> Ball {

    var anchorPoint = CGPointMake(0.5, 0.5)

    // Half Circle #1

    let myCrop1 = SKCropNode()

    let myMask1 = SKSpriteNode(color: UIColor.blackColor(), size: CGSizeMake(100, 100))
    myMask1.position.y = -50

    let ball = SKShapeNode(circleOfRadius: 50)
    ball.lineWidth = 0
    ball.fillColor = UIColor.blueColor()

    myCrop1.addChild(ball)
    myCrop1.maskNode = myMask1
    addChild(myCrop1) //ERROR HERE

    // Half Circle #2

    let myCrop2 = SKCropNode()

    let myMask2 = SKSpriteNode(color: UIColor.blackColor(), size: CGSizeMake(100, 100))
    myMask2.position.y = 50

    let circle2 = SKShapeNode(circleOfRadius: 50)
    circle2.lineWidth = 0
    circle2.fillColor = UIColor.redColor()

    myCrop2.addChild(circle2)
    myCrop2.maskNode = myMask2
    addChild(myCrop2)


    return ball
1

There are 1 best solutions below

0
John Spalluzzi On

Change the function away from being static.

When you make a function or a static, it belongs to the class rather than an instance of the class.

When you call addChild(myCrop1) you are really saying: self.addChild(myCrop1). That self, is referring to an instance, which is not allowed in a static function.