精灵套件精灵未正确遵循路径



我目前正在将我的安卓游戏转换为iOS,我试图让蝙蝠敌人"俯冲"玩家。我在 SpriteKit 中创建了曲线,它看起来不错,但是蝙蝠似乎没有正确跟随这条线,它会消失几秒钟,然后向上滑过右上角,尽管运行了一个动作。路径附加到跟随玩家的 shapeNode。

法典:

func createPath(){
//All x values are moved back 1 / 4 of the screens width due to the camera being 1 / 4 of the screens width ahead of the player, and y values are halved due to the player being in the centre of y axis
path.move(to: CGPoint(x: gameScene.frame.width * 3 / 4, y: gameScene.frame.height / 2)) //top right corner
path.addCurve(to: CGPoint(x: -(gameScene.frame.width / 3.5), y: gameScene.frame.height / 6), control1: CGPoint(x: gameScene.frame.width / 2,  y: -(gameScene.frame.height / 9)), control2: CGPoint(x: 0, y: -(gameScene.frame.width / 9)))
//to = off screen
//control1 3 / 4 across screen, slighly higher than player
//control2 exactly on player (players node height is screen width / 4.5)
followLine = SKAction.follow(path, asOffset: true, orientToPath: false, duration: 3)
viewLine.path = path
gameScene.addChild(viewLine)
}
func update(dt: Double){
if(GameScene.gV.distanceM == 4 && !run){//DistanceM is just a timer (seconds)
run = true
bat.run(followLine)
}
if run {
/*time += dt//timer to reset bats position
if time > 4 {
run = false
time = 0
}*/
} else {
bat.position = CGPoint(x: gameScene.pigeonCam.position.x + gameScene.frame.width / 2, y: gameScene.pigeonCam.position.x + gameScene.frame.height / 2)//keep bat at top right of screen
}
viewLine.position = gameScene.pigeon.pigeon.position//get node to follow the player
}

我最好的猜测是,虽然移动 shapeNode 似乎移动了路径,但它实际上并没有移动,如果是这样,我可以通过任何其他方式让这条路径"跟随"玩家

经过多次试验和错误,我意识到 asOffset 所指的节点是运行操作的节点,所以我将球棒放在屏幕的右上角并调整了值,我的最终值如下所示:

let width = gameScene.frame.width
let height = gameScene.frame.height
path.move(to: CGPoint(x: 0, y: 0)) //top right corner
//0, 0
path.addCurve(to: CGPoint(x: -(width * 1.2), y: -(height / 3.5)), control1: CGPoint(x: -(width / 4),  y: -(height / 1.5)), control2: CGPoint(x: -(width * 3 / 4), y: -(height / 2)))

这使得蝙蝠完美地遵循线条,尽管线条的视觉表示被搞砸了

最新更新