我正在为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()
}
}