我的iOS游戏应用无法使用设备

时间:2018-03-30 07:10:27

标签: ios sprite-kit skspritenode gameplay-kit

我在Xcode中使用SpriteKit创建了一个小型iOS游戏应用程序。它在模拟器上正常工作,但在设备中它不会创建节点。在我设置为动态创建节点的代码中,它正在工作 在模拟器上但不在设备上工作

在模拟器上 enter image description here

在设备上 enter image description here

@objc func createRoadStrip(){
    let leftRoadStrip = SKShapeNode(rectOf: CGSize(width: 10, height: 60))
    leftRoadStrip.strokeColor = .white
    leftRoadStrip.fillColor = .white
    leftRoadStrip.position.x = -187
    leftRoadStrip.position.y =  700
    leftRoadStrip.zPosition = 10
    leftRoadStrip.alpha = 0.4
    leftRoadStrip.name = "leftRoadStrip"
    addChild(leftRoadStrip)

    let rightRoadStrip = SKShapeNode(rectOf: CGSize(width: 10, height: 60))
    rightRoadStrip.strokeColor = .white
    rightRoadStrip.fillColor = .white
    rightRoadStrip.position.x = 187
    rightRoadStrip.position.y =  700
    rightRoadStrip.zPosition = 10
    rightRoadStrip.alpha = 0.4
    rightRoadStrip.name = "rightRoadStrip"

    addChild(rightRoadStrip)

}



func moveRoadStrip(){
    enumerateChildNodes(withName: "leftRoadStrip") { (strip, stop) in
        let leftRoadStrip = strip as! SKShapeNode
        leftRoadStrip.position.y -= 40
    }

    enumerateChildNodes(withName: "rightRoadStrip") { (strip, stop) in
        let rightRoadStrip = strip as! SKShapeNode
        rightRoadStrip.position.y -= 40
    }

}

 override func update(_ currentTime: TimeInterval) {
   //here
    moveRoadStrip()
    moveTrafficCar()
    if(carCanMove){
        moveCar(toLeftSide: leftCarToMoveLeft)
        moveCar(toRightSide: rightCarToMoveRight)
    }
    removeItems()
}

我在didMove方法中调用Timer(创建道路条)并在更新功能中移动道路条

 override func didMove(to view: SKView) {
    self.anchorPoint = CGPoint(x: 0.5, y: 0.5)
    physicsWorld.contactDelegate = self
    setUp()
    Timer.scheduledTimer(timeInterval: 0.2, target: self, selector: #selector(createRoadStrip), userInfo: nil, repeats: true)
}


override func update(_ currentTime: TimeInterval) {
   //here
    moveRoadStrip()
}

我的设备版本是

  • iOS:9.0,型号iPhone 6

0 个答案:

没有答案