1
votes

I'm making my first game with Swift and SpriteKit and have noticed that my game quickly approaches 100% CPU use. I have been posting a lot about this recently, but here I'm now I'm now attempting to pull it apart to determine where my problems are. I originally thought my problem was with instantiating new enemies, so I removed everything but the small user-controlled spaceship and its shooting functionality. However, I'm still hitting 100% after a couple minutes of "play". I'm using the time-profiler instrument to try and figure out whats going on but I'm having trouble. I've broken up the time line:

Here is the first subgraph when the user clicks a homeScene button to enter the GameScene.enter image description here

I'm not entirely sure what the red and yellow "Heaviest backtraces" with 3256x and 861x respectively mean, but from tutorials I've seen I would imagine that they are abnormally high. Here is the Call Tree as well:enter image description here

I'm also not entirely sure why the controller textures would be using so much as they are simply setting two textures in the file right before the GameScene class:

let controllerBaseTexture = SKTextureAtlas(named:"Sprites").textureNamed("controllerBase")
let controllerHandleTexture = SKTextureAtlas(named:"Sprites").textureNamed("controllerHandle")

class GameScene: SKScene, SKPhysicsContactDelegate {

Then here is the Call Tree when the game starts and when the CPU reaches 100%: enter image description here

I'm also confused about what "UnsaveMutableAddressors" are, as I see them very commonly when trying to debug this code.

I know this is a lot, but I'm not sure where to begin. Any suggestions would be awesome. I would also like to know if there are good resources on how to interpret this better because I've gone through a handful and I'm still very stuck.

Thanks for any help!

1
Have you actually counted the number of times startGame is called? In theory it should be called only once right?Mobile Ben
You are calling GameScene.init from each update() call. Fix the basic logic of your game since this is clearly not the right kind of thing to be doing in an update.MoDJ
@MobileBen @ MoDJ Are you talking strictly about the beginning section-- during the load? Because there is delay there and that would make sense, but the real problem is the CPU use during game play (the middle section) which doesn't have any AlienAnnhilator specific reference?muZero
Sam, you need to not do the init() logic from the update() call. Create the objects and layout once but don't created instances of things on every update call. You have to keep in mind that update() is invoked 60 times a second and structure your code properly.MoDJ

1 Answers

1
votes

The profiler shows it's something in your update method for your gameScene. Keep in mind this gets ran around 60 times per second so you don't want to do anything extremely heavy there.