gpt4 book ai didi

swift - 无法将 "inout CGAffineTransform"类型的值转换为预期参数

转载 作者:行者123 更新时间:2023-11-30 10:01:40 27 4
gpt4 key购买 nike

我试图让玩家在路径中改变方向,问题是每次运行应用程序时都会弹出错误“无法将“inout CGAffineTransform”类型的值转换为预期参数。 ”

 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")

}

最佳答案

我建议将您的代码更改为:

    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")
<小时/>

来自Apple的文档Interacting with C API's

Constant Pointers

When a function is declared as taking a UnsafePointer argument, it can accept any of the following:

  • nil, which is passed as a null pointer.
  • An UnsafePointer, UnsafeMutablePointer, or AutoreleasingUnsafeMutablePointer value, which is converted to UnsafePointer if necessary.
  • A String value, if Type is Int8 or UInt8. The string will automatically be converted to UTF8 in a buffer, and a pointer to that buffer is passed to the function.
  • An inout expression whose left-hand side operand is of type Type, which is passed as a pointer to the address of the left-hand side identifier.
  • A [Type] value, which is passed as a pointer to the start of the array.

第四个项目符号告诉我们您可以发送 &mirroring对于期待 UnsafePointer<CGAffineTransform> 的参数.

关于swift - 无法将 "inout CGAffineTransform"类型的值转换为预期参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38176032/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com