如果你只需要它们从上到下没有任何特殊的曲线轨迹,那么你不需要处理样条曲线。
让我们先解决渐进加速。你希望他们在开始时缓慢下降,并在比赛进程中加速。一种方法是跟踪级别时间并根据经过的级别时间进行一些持续时间数学计算。一个更容易的方法是减少小行星到达底部的时间。在你的场景声明部分,声明这些:
fileprivate let startingDuration: TimeInterval = 6.0 // Put here whatever value you feel fit for the level start falling speed
fileprivate let difficultyIncrease: TimeInterval = 0.05 // Put here whatever value you feel fit for how much should each next asteroid accelerate
fileprivate let collisionPosition = CGPoint(x: 300, y: 200) // Put here the onscreen location where the asteroids should be heading to
fileprivate var asteroidCounter = 0 // Increase this counter every time you spawn a new asteroid
现在,我们来看看实际的小行星运动。有不同的方式来处理它。苹果推荐的最简单的方法就是为此采取行动。此代码添加到您的小行星产卵方法:如果你需要随机整数生成功能
// Implement here your spawning code ...
// It's best to choose random starting points (X axis) a bit higher than the upper screen boundary
let fallingDuration: TimeInterval = startingDuration - difficultyIncrease * TimeInterval(asteroidCounter)
let fallingAction = SKAction.move(to: collisionPosition, duration: fallingDuration)
asteroid.runAction(fallingAction)
,试试这个:
func RandomInt(min: Int, max: Int) -> Int {
return Int(arc4random_uniform(UInt32(max-(min-1)))) + min
}
问题太多...尝试专注于一个特定的问题。否则,你的问题可能会被关闭。关于你的问题的提示很少......如果你的岩石会沿着直线走,你不需要更加缓慢的路径。你可以使用动作产卵/移动/移除岩石。 – Whirlwind