Can not solve this problem ?
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)
}
}
})
}
I am not sure if this is still applicable in the latest version of swift but:
/*
* Copyright (c) 2013-2014 Razeware LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
This file has been truncated. show original
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.
system
Closed
May 20, 2019, 12:28am
8
This topic was automatically closed after 166 days. New replies are no longer allowed.