官术网_书友最值得收藏!

Renovating the GameScene class

We have made quite a few changes to our project. Luckily, this is the last major overhaul of the previous animation code. Moving forward, we will use the terrific structure we built in this chapter. At this point, your GameScene.swift file should look something like the following:

import SpriteKit

class GameScene: SKScene { 
    let cam = SKCameraNode() 
    let ground = Ground() 
    let player = Player() 

    override func didMove(to view: SKView) { 
self.anchorPoint = .zero 
self.backgroundColor = UIColor(red: 0.4, green: 0.6, blue: 
            0.95, alpha: 1.0) 

        // Assign the camera to the scene 
self.camera = cam 


        // Spawn our test bees: 
        let bee2 = Bee() 
bee2.position = CGPoint(x: 325, y: 325) 
self.addChild(bee2) 
        let bee3 = Bee() 
bee3.position = CGPoint(x: 200, y: 325) 
self.addChild(bee3) 

        // Add the ground to the scene: 
ground.position = CGPoint(x: -self.size.width * 2, y: 150) 
ground.size = CGSize(width: self.size.width * 6, 
               height: 0) 
ground.createChildren() 
self.addChild(ground) 

        // Add the player to the scene: 
player.position = CGPoint(x: 150, y: 250) 
self.addChild(player) 
    } 

    override func didSimulatePhysics() { 
        // Keep the camera centered on the player 
self.camera!.position = player.position
    } 
} 

Run the project. You will see our new penguin hovering near the bees. Great work; we are now ready to explore the physics system with all of our new nodes. Your simulator should look something like this screenshot:

Renovating the GameScene class
主站蜘蛛池模板: 通州区| 齐齐哈尔市| 区。| 嵩明县| 和顺县| 沈丘县| 万源市| 孟村| 长丰县| 凤台县| 菏泽市| 兰坪| 齐齐哈尔市| 濮阳县| 旺苍县| 娱乐| 白银市| 青海省| 台州市| 大埔县| 潮州市| 青岛市| 化州市| 射洪县| 霍邱县| 杭锦旗| 肇源县| 龙岩市| 平乡县| 和平区| 阿巴嘎旗| 桃江县| 峨边| 千阳县| 呼图壁县| 全州县| 临潭县| 杂多县| 九台市| 新竹市| 潞城市|