我正在使用下面的代码将我的精灵从一个位置移动到另一个位置。
let screenScale: CGFloat = UIScreen.mainScreen().scale
var travelSpeed: CGFloat = 20*screenScale
let displacement = CGVector(dx: destination.x-enemy!.sprite.position.x, dy: destination.y-enemy!.sprite.position.y)
let radius = sqrt(displacement.dx*displacement.dx+displacement.dy*displacement.dy)
let normal = CGVector(dx: displacement.dx/radius, dy: displacement.dy/radius)
let impulse = CGVector(dx: normal.dx*travelSpeed, dy: normal.dy*travelSpeed)
let relativeVelocity = CGVector(dx:impulse.dx-enemy!.sprite.physicsBody!.velocity.dx, dy:impulse.dy-enemy!.sprite.physicsBody!.velocity.dy);
enemy!.sprite.physicsBody!.velocity=CGVectorMake(enemy!.sprite.physicsBody!.velocity.dx+relativeVelocity.dx*rate, enemy!.sprite.physicsBody!.velocity.dy+relativeVelocity.dy*rate);
但是当我在iPhone 6S Plus上进行测试时,精灵的移动速度比我的iPhone 5快得多。我认为下面的线条适合不同的尺寸,因为我使用的是屏幕尺度:
var travelSpeed: CGFloat = 20*screenScale
或者我错过了什么?