SKSpriteNodes没有正确显示

时间:2018-04-08 07:50:43

标签: ios swift xcode sprite-kit skspritenode

我试图制作一个“弹出锁定”。喜欢游戏有点乐趣和练习,但我的SKSpriteNodes根本没有出现。我的GameScene.swift和我的GameViewController.swift一样。我已经使用Sprite Kit查看了其他人的项目,他们都工作正常,但他们的代码也没有用。

enter image description here

enter image description here

enter image description here

   import UIKit
import SpriteKit
import GameplayKit

class GameViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        if let view = self.view as! SKView? {
            if let scene = SKScene(fileNamed: "GameScene") {
                scene.scaleMode = .aspectFill

                view.presentScene(scene)
            }

            view.ignoresSiblingOrder = true

            view.showsFPS = true
            view.showsNodeCount = true
        }
    }

    override var shouldAutorotate: Bool {
        return true
    }

    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        if UIDevice.current.userInterfaceIdiom == .phone {
            return .allButUpsideDown
        } else {
            return .all
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    override var prefersStatusBarHidden: Bool {
        return true
    }
}
    import SpriteKit
import GameplayKit

class GameScene: SKScene {

    var circle = SKSpriteNode()
    var tapper = SKSpriteNode()

    var tapperPath = UIBezierPath()

    var gameStarted = Bool()

    var movingClockwise = Bool()

    override func didMove(to view: SKView) {

        circle = SKSpriteNode(imageNamed: "Circle")
        circle.size = CGSize(width: 300, height: 300)
        circle.position = CGPoint(x: UIScreen.main.bounds.width/2, y: UIScreen.main.bounds.height/2)
        self.addChild(circle)

        tapper = SKSpriteNode(imageNamed: "Tapper")
        tapper.size = CGSize(width: 40, height: 7)
        tapper.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2 + 120)
        tapper.zRotation = 3.14 / 2
        self.addChild(tapper)

    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

        if gameStarted {
            if movingClockwise {
                moveCounterClockWise()
                movingClockwise = false
            } else {
                moveClockWise()
                movingClockwise = true
            }
        } else {
            moveClockWise()
            movingClockwise = true
            gameStarted = true
        }
    }


    func moveClockWise() {

        let dx = tapper.position.x - self.frame.width / 2
        let dy = tapper.position.y - self.frame.height / 2

        let rad = atan2(dy, dx)

        tapperPath = UIBezierPath(arcCenter: CGPoint(x: self.frame.width / 2, y: self.frame.height / 2), radius: 120, startAngle: rad, endAngle: rad + (CGFloat.pi * 4), clockwise: true)
        let follow = SKAction.follow(tapperPath.cgPath, asOffset: false, orientToPath: true, speed: 200)
        tapper.run(SKAction.repeatForever(follow).reversed())

    }

    func moveCounterClockWise() {

        let dx = tapper.position.x - self.frame.width / 2
        let dy = tapper.position.y - self.frame.height / 2

        let rad = atan2(dy, dx)

        tapperPath = UIBezierPath(arcCenter: CGPoint(x: self.frame.width / 2, y: self.frame.height / 2), radius: 120, startAngle: rad, endAngle: rad + (CGFloat.pi * 4), clockwise: true)
        let follow = SKAction.follow(tapperPath.cgPath, asOffset: false, orientToPath: true, speed: 200)
        tapper.run(SKAction.repeatForever(follow))

    }


    override func update(_ currentTime: TimeInterval) {

    }
}

修改

.sks文件:

enter image description here

0 个答案:

没有答案