Diego Benítez Diego Benítez - 5 months ago 22
Swift Question

cannot convert value of type "inout CGAffineTransform" to expected argument

I am trying to make the player change of direction while is in a path, the problem is that every time I run the app it pop out an error of "cannot convert value of type "inout CGAffineTransform" to expected argument..."

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */

if gameStarted == false {

gameStarted = true
moveClockWise()
movingClockWise = true


var myCircle : CGMutablePath! = CGPathCreateMutable()
let newDx = player.position.x - self.frame.width / 2
let newDy = player.position.y - self.frame.height / 2
let newRad = atan2(newDy, newDx)
let newPath = UIBezierPath(arcCenter: CGPoint(x:self.frame.width / 2, y: self.frame.height / 2) , radius: 170, startAngle: newRad, endAngle: newRad + CGFloat(M_PI * 4), clockwise: true)

var mirroring = CGAffineTransformMakeScale(1.0, -1.0) // flip horizontal
var mirrorPath : CGMutablePath! = CGPathCreateMutable()
let finalPath = withUnsafeMutablePointer(&mirroring)//Here it tells me the error
{
CGPathAddPath(mirrorPath, UnsafeMutablePointer($0), newPath.CGPath!)
}

let newFollow = SKAction.followPath(mirrorPath, asOffset: false, orientToPath: true, speed: 200)
player.runAction(SKAction.repeatActionForever(newFollow).reversedAction(),withKey:"followPath")


}else {
player.removeActionForKey("followPath")
}

}

func moveClockWise(){

let dx = player.position.x - self.frame.width / 2
let dy = player.position.y - self.frame.height / 2

let rad = atan2(dy, dx)

path = UIBezierPath(arcCenter: CGPoint(x:self.frame.width / 2, y: self.frame.height / 2) , radius: 170, startAngle: rad, endAngle: rad + CGFloat(M_PI * 4), clockwise: true)

let follow = SKAction.followPath(path.CGPath, asOffset: false, orientToPath: true, speed: 200)
player.runAction(SKAction.repeatActionForever(follow).reversedAction(),withKey:"followPath")

}

Answer

I suggest changing your code to:

    var mirroring = CGAffineTransformMakeScale(1.0, -1.0) // flip horizontal
    var mirrorPath : CGMutablePath! = CGPathCreateMutable()
    CGPathAddPath(mirrorPath, &mirroring, newPath.CGPath)

    let newFollow = SKAction.followPath(mirrorPath, asOffset: false, orientToPath: true, speed: 200)
    player.runAction(SKAction.repeatActionForever(newFollow).reversedAction(),withKey:"followPath")
Comments