if gameStarted == false {
let spawn = SKAction.run({
() in
self.createPlatforms()
})
let delay = SKAction.wait(forDuration: 1.5)
let spawnDelay = SKAction.sequence([spawn, delay])
let spawnDelayForever = SKAction.repeatForever(spawnDelay)
self.run(spawnDelayForever)
let distance = CGFloat(self.frame.width + platformPair.frame.width)
let movePlatforms = SKAction.moveBy(x: -distance, y: 0, duration: TimeInterval(0.01 * Double(distance))
let removePlatforms = SKAction.removeFromParent()
moveAndRemove = SKAction.sequence([movePlatforms, removePlatforms])
player.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
player.physicsBody?.applyImpulse(CGVector(dx: 0,dy: 150))
} else {
player.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
player.physicsBody?.applyImpulse(CGVector(dx: 0,dy: 150))
}
我在x
let movePlatforms
函数中由于moveBy
值不断收到此错误:
无法将类型'CGFloat'的值转换为预期的参数类型'CGVector'
距离是CGFloat
,并且x
方法中的moveBy
参数是CGFloat
。不知道为什么它不起作用。
您在此行上缺少右括号:
let movePlatforms = SKAction.moveBy(x: -distance, y: 0, duration: TimeInterval(0.01 * Double(distance)))