0

I'm working on a Mario Clone for Mac and would like to make the player jump on a curved line when the right and up arrow are pressed.
I've heard about UIBezierPaths being the solution to this, but sadly I have no clue how to use them.

Can someone please explain what code I would write in order to make a UIBezierPath as well as make Mario follow the path in a jump?

Thank you.

Somewhat of the way I would like my player to jump: !http://projects.haskell.org/diagrams/doc/images/d8527a0188182ef5.png

My Player Movements So far:

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()
    }
}
boraseoksoon
  • 2,164
  • 1
  • 20
  • 25
  • Look at this : https://developer.apple.com/library/content/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/BezierPaths/BezierPaths.html – Janmenjaya Sep 29 '16 at 01:09
  • @Janmenjaya just read that as well as another apple developer document. Apparently UIKit is only for iOS and tvOS? Would that mean I can't use UIbezier paths in my game? because I am developing for mac. – Gaurav Manchanda Sep 29 '16 at 02:07

0 Answers0