2017-09-25 179 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的发布。