O'Reilly logo

Swift Game Development - Third Edition by Stephen Haney, Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating the hero class and physics

Create a new class, called Hero, and add the following code to it:

import SceneKit
class Hero: SCNNode {
    
    var isGrounded = false
    
    var monsterNode = SCNNode()
    var jumpPlayer = SCNAnimationPlayer()
    var runPlayer = SCNAnimationPlayer()
    
    init(currentScene: GameSCNScene){
        super.init()
        self.create(currentScene: currentScene)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func create(currentScene: GameSCNScene){
    
    }
} 

At the top of the create variables, which we will be needing later, we create a bool to check whether the character is grounded or not. Create a SCNNode to access the character node and create two SCNAnimationPlayer variables to access the player animations. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required