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
//**Where this function is called:** (last line of this function)

  override func update(currentTime: CFTimeInterval) {
        scoreLabel.text =  scoreVarInLabel + String(accessVar.gameScore)

            pixelman.position.x = 20
            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




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

All Articles