游戏仅在 iPhone X 和 iPhone 8 Plus 上崩溃

Game crash only on iPhone X and iPhone 8 Plus

我正在开发游戏,游戏在所有 iPhones 和 iPad 上运行完美,预计 iPhone X 和 iPhone 8 Plus

当我将精灵添加到场景时游戏崩溃(仅在 iPhone X 和 iPhone 8 Plus 上)因为精灵已经添加到场景中,在其他 iPhone 上应用程序没有崩溃,我认为错误出在我的计时器中,也许错误是 iPhone 模拟器?你怎么看?

代码:

  class GameScene: SKScene, SKPhysicsContactDelegate {

var finger = SKSpriteNode(imageNamed: "Finger") //Finger to swipe the biscuit

var biscuit = SKSpriteNode(imageNamed: "Biscuit")

var glass = SKSpriteNode(imageNamed: "Glass")

var defaultbiscuitpos:CGPoint = CGPoint()

var defaultfingerpos:CGPoint = CGPoint()

/*** Drag Biscuit vars ***/
var touchpoint:CGPoint = CGPoint()
var istouching:Bool = false

var fadeoutfinger = SKAction()
var fadeinfinger = SKAction()
var fingergroup = SKAction()
var burnanimtion = SKAction()
var movefinger = SKAction()

let fingertimer:String = "fingertimer"

var isGameover:Bool = false

//Game mode enum

enum gamemode {
case dip
case ready
case out
case gameover

}

//Game mode (Dip,Ready,Out or game over by enum) **Now is Dip
var mymode = gamemode.dip

override func didMove(to view: SKView) {

 //Finger
finger.name = "Finger"
finger.position = CGPoint(x: biscuit.position.x + finger.frame.width, y: biscuit.position.y)
defaultfingerpos = finger.position
finger.alpha = 1.0
finger.zPosition = 5

//Start finger timer to make animation
    createTimer(name: fingeranimation, waitt: 3.0, sprite: finger, actioname: fingertimer)

 }

//Finger timer func
func fingeranimation () {


//Check if timer is over 4 seconds and the title is dip
if mymode == gamemode.dip {

    //Add finger to screen
    addChild(finger)

    //Set fade in animation for finger
    fadeinfinger = SKAction.fadeIn(withDuration: 2.0)

    //Set move animation for finger
    movefinger = SKAction.moveTo(y: glass.frame.midX, duration: 2.0)

    //Set fade out animation for finger
    fadeoutfinger = SKAction.fadeOut(withDuration: 2.0)

    fingergroup = SKAction.group([fadeinfinger,movefinger,fadeoutfinger])

    finger.run(fingergroup, completion: {

        //Remove finger from screen
        self.finger.removeFromParent()

        //Return the finger to apper and return the finger to default position
        self.finger.alpha = 1.0
        self.finger.position = self.defaultfingerpos

      })

   }

  }

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

let touch = touches.first! as UITouch
let location = touch.location(in: self)

//Tap on biscuit
if biscuit.contains(location) && mymode != gamemode.gameover   {
    touchpoint = location
    istouching = true
    biscuit.physicsBody?.pinned = false

    //Stop the finger animation timer
    stopTimer(actioname: fingertimer, sprite: finger)
  }
}

//Make timer function
func createTimer (name:@escaping os_block_t , waitt:TimeInterval, sprite:SKSpriteNode?,actioname: String) {

    let myaction = SKAction.sequence([SKAction.wait(forDuration: waitt), SKAction.run(name)])

    run(SKAction.repeatForever(myaction), withKey: actioname)
}

//Stop timer function
  func stopTimer(actioname:String, sprite:SKSpriteNode?) {

  removeAction(forKey: actioname)
}

override func update(_ currentTime: TimeInterval) {

// Called before each frame is rendered
if istouching && isGameover == false {
    let dt:CGFloat = 1.0/15
    let distance = CGVector(dx: touchpoint.x - biscuit.position.x, dy: touchpoint.y - biscuit.position.y * 1.65)
    let velocity = CGVector(dx: distance.dx/dt, dy: distance.dy/dt)
    self.biscuit.physicsBody!.velocity = velocity

    }
  }
}

此问题现已随着 Xcode 9.1 的发布得到解决。