This simple game uses extremely high CPU utilization
I have a game in which garbage appears and the player has to dodge it, and the debris is generated by a function that calls a function in it addAlien
. This feature is called updateWithTimeSinceLastUpdate()
. The problem is that it uses as much as 80% of the CPU and I have no idea why ... When I uninstall it, the application works fine, but with it it crashes. Can anyone tell me what should I do to fix this? All help is greatly appreciated: Code given below
func updateWithTimeSinceLastUpdate(timeSinceLastUpdate: CFTimeInterval){
lastYieldTimeInterval += timeSinceLastUpdate
if(lastYieldTimeInterval > 1){
lastYieldTimeInterval = 0
addAlien()
}
}
//**Where this function is called:** (last line of this function)
override func update(currentTime: CFTimeInterval) {
scoreLabel.text = scoreVarInLabel + String(accessVar.gameScore)
if(pixelman.position.x<20){
pixelman.position.x = 20
}
if(pixelman.position.x>self.frame.width-5){
pixelman.position.x = self.frame.width-5
}
var timeSinceLastUpdate = currentTime - lastUpdateTimerInterval
lastUpdateTimerInterval = currentTime
if(timeSinceLastUpdate > 1){
timeSinceLastUpdate = 1/60
lastUpdateTimerInterval = currentTime
}
// The below line is what is causing 80% CPU Usage
updateWithTimeSinceLastUpdate(timeSinceLastUpdate)
}
Thank you so much in advance
As a side note, I apologize for the specifics of the question: I want to generally understand what is causing this crash.
source to share
No one has answered this question yet
Check out similar questions: