我想知道是否有人知道如何实现类似Gameppy of Flappy Bird的相机效果。过去通过移动相机看起来像游戏中发生了地震。
由于
答案 0 :(得分:0)
我可以想到两种可能对您有用的有效方法。在将视图切换到场景中的游戏之前,可以在update
功能中随机调整相机的位置几次,或者使用着色器放大到当前场景并执行类似的操作。
至于使用更新,我可能会建议:
创建以下枚举和变量:
enum ShakeDirection: Int {
case up = 0
case down
case left
case right
}
var currentShakeDirection = ShakeDirection.up
override func update(currentTime: CFTimeInterval) {
//Set this to true twice every 60 iterations (Since there are about 60 fps for most games, a random variable between 0 and 59 will be less than or equal to 1 about twice per second)
let switchDirection: Bool = (arc4_random(60) <= 1)
if switchDirection {
let rawIndex = Int(arc4random(4))
currentShakeDirection = currentShakeDirection(rawValue: rawIndex)
}
switch currentShakeDirection {
case .up:
let x = camera.position.x
let y = camera.position.y + 1
camera.position = CGPoint(x: x, y: y)
case .down:
let x = camera.position.x
let y = camera.position.y - 1
camera.position = CGPoint(x: x, y: y)
case .left:
let x = camera.position.x - 1
let y = camera.position.y
camera.position = CGPoint(x: x, y: y)
case .right:
let x = camera.position.x + 1
let y = camera.position.y
camera.position = CGPoint(x: x, y: y)
}
}
这只是一种可能的实现,并且有很多不同的选择。这将无限期地继续下去,因此我将根据需要设置一种方法来启动和停止它。