Flappy Felipe Video Tutorial : (Swift4.2) Update

Can not solve this problem ? :thinking:
Video tutorial: Flappy Felipe for Swift 3

I use Xcode 10.1 Swift 4.2

Binary operator ‘+=’ cannot be applied to two ‘CGPoint’ operands

    func updateForeground(){
    worldNode.enumerateChildNodes(withName: "foreground", using: { node, stop in
        if let foreground = node as? SKSpriteNode{
            let moveAmount = CGPoint(x: -self.groundSpeed * CGFloat(self.deltaTime), y: 0)
    foreground.position += moveAmount
    if foreground.position.x < -foreground.size.width{
    foreground.position += CGPoint(x: foreground.size.width * CGFloat(self.numberOfForegrounds), y: 0)
            }    
        }
    })
}

47

I am not sure if this is still applicable in the latest version of swift but:

I believe the part you are looking for is:

/**

  • Adds two CGPoint values and returns the result as a new CGPoint.
    */
    public func + (left: CGPoint, right: CGPoint) → CGPoint {
    return CGPoint(x: left.x + right.x, y: left.y + right.y)
    }

/**

1 Like

Yeah! , thanks a lot, but I don’t know how can I use It.
I am new on Swift … , but I try it !

Be sure to ask if you need more help with it!

I ´ve solved this problem!

func updateForeground(){
    worldNode.enumerateChildNodes(withName: "foreground", using: { node, stop in
        if let foreground = node as? SKSpriteNode {
            let moveAmount = CGPoint(x: -self.groundSpeed * CGFloat(self.deltaTime), y: 0)
            
            foreground.position = CGPoint(x: foreground.position.x + moveAmount.x, y: foreground.position.y + moveAmount.y)
            
            let Point = CGPoint(x: foreground.size.width * CGFloat(self.numberOfForegrounds), y: 0)
            
            if foreground.position.x < -foreground.size.width{
                foreground.position = CGPoint(x: foreground.position.x + Point.x, y: foreground.position.y + Point.y)
            }
          
        }
    })
}

@emindagci Thank you for sharing the solution - much appreciated! :]

The file quoted contains a lot of extensions for Apple’s inbuilt CGPoint for functionality that is not supplied by default. It includes instructions to the compiler on how to add two CGPoints [public func + (left: CGPoint, right: CGPoint) -> CGPoint] and an implementation for the += operator; as well as the ability to add a CGVector to a CGPoint.

This file needs to be added to your project; and then you can ‘magically’ call the code you have above and it will work, so no need for you to implement this yourself.

This topic was automatically closed after 166 days. New replies are no longer allowed.