gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:08:13 26 4
gpt4 key购买 nike

我正在开发游戏,该游戏在所有 iPhone 和 iPad 上都能完美运行,除了 iPhone X 和 iPhone 8 Plus

当我将 Sprite 添加到场景时,游戏崩溃(仅在 iPhone X 和 iPhone 8 Plus 上),因为 Sprite 已经添加到场景中,在其他 iPhone 上,应用程序不会崩溃,我认为错误可能出在我的计时器中是iPhone模拟器的bug吗?你觉得怎么样?

代码:

  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 的发布得到解决。

关于swift - 仅在 iPhone X 和 iPhone 8 Plus 上游戏崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46413449/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com