2017-09-25 176 views
0

我工作的遊戲和遊戲完美的作品在所有的iPhone和iPad的期待iPhone X和iPhone 8加遊戲崩潰

當我加雪碧現場遊戲崩潰(只在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 

    } 
    } 
} 
+0

X和其他模擬器沒有區別。你需要在這裏清理你的代碼,以便它可讀。現在我不知道發生了什麼,因爲我無法區分什麼時候我們在課堂上或什麼時候我們在功能 – Knight0fDragon

+0

我編輯我的代碼,你在GameScene類 –

+1

這段代碼仍然會失敗,你的創建計時器是浮動 – Knight0fDragon

回答

0

此問題是現在固定在Xcode 9.1的發佈。