UIBezier路径,节点跳转

时间:2016-09-29 00:31:09

标签: ios swift macos macos-sierra

我正在为Mac制作一个马里奥克隆人,并希望当按下右箭头和向上箭头时让玩家跳到曲线上。我听说过关于UIBezierPaths是解决这个问题的方法,但遗憾的是我不知道如何使用它们。

有人可以解释为了制作UIBezierPath我会编写什么代码以及让马里奥在跳跃中沿着路径前进?

谢谢。

我想让我的玩家跳起来的方式有点像: !http://projects.haskell.org/diagrams/doc/images/d8527a0188182ef5.png

我的玩家动作到目前为止:

func jump(){
    // 250 , 120
    let jumpUp = SKAction.moveTo(y: 250, duration: 0.25)
    let jumpDown = SKAction.moveTo(y: 120, duration: 0.25)
    let jumpSequence = SKAction.sequence([jumpUp,jumpDown])

    player.run(jumpSequence)   
}

func userMoveRight(){
    player.xScale = 0.23
    level.run(SKAction.sequence([SKAction.moveBy(x: -20, y: 0, duration: 0.2)]))
    background.run(SKAction.sequence([SKAction.moveBy(x: -20, y: 0, duration: 0.2)]))
    question.run(SKAction.sequence([SKAction.moveBy(x: -20, y: 0, duration: 0.2)]))
}

func userMoveLeft(){
    player.xScale = -0.23
    background.run(SKAction.sequence([SKAction.moveBy(x: 20, y: 0, duration: 0.2)]))
    level.run(SKAction.sequence([SKAction.moveBy(x: 20, y: 0, duration: 0.2)]))
    question.run(SKAction.sequence([SKAction.moveBy(x: 20, y: 0, duration: 0.2)]))
} 

override func keyDown(with theEvent: NSEvent) {
    let keyCode = theEvent.keyCode

    //Moving Right
    if keyCode == 124 {
        userMoveRight()
    }

    //Moving Left
    if player.position.x <= 490, background.position.x <= 1513, keyCode == 123 {
        userMoveLeft()    
    }

    //Jump
    if keyCode == 126 , player.position.y == 120 {   
        jump()
    }
}

0 个答案:

没有答案