我有一个问题,我想在没有匹配类型的操作中使用变量。因此,我收到以下错误:Cannot convert value of type 'SKSpriteNode' to expected argument type 'CGPoint'
。
func enemyProofNextFields() {
for i in 0...41 {
if getDistance(knightRed.position, grassTileArray[i].position) > 120 && getDistance(knightRed.position, grassTileArray[i].position) < 121 {
possibleEnemeyFields.append(grassTileArray[i])
}
}
var lenght = possibleEnemeyFields.count
let randomNumber = Int.random(in: 0 ... lenght)
print("Random Enemy Number: \(randomNumber)")
var position = possibleEnemeyFields[randomNumber]
let move = SKAction.move(to: position, duration: 0.3) //here is the error
knightRed.run(SKAction.sequence([move]))
}
对于任何回答,我将非常感谢。
答案 0 :(得分:2)
错误非常明显:possibleEnemeyFields
显然包含SKSpriteNode
个实例,但是move
的第一个参数期望一个CGPoint
,假定为position
>
您可能是说
let field = possibleEnemeyFields[randomNumber]
let move = SKAction.move(to: field.position, duration: 0.3)