Some issues in Sprite Kit I've found.

Discussion in 'Public Game Developers Forum' started by Mad Pig Games, Nov 30, 2014.

  1. Mad Pig Games

    Mad Pig Games Well-Known Member

    Oct 12, 2011
    45
    0
    0
    Game Developer
    Hello,

    I thought I'd share some issues I've found in Sprite Kit while working on my new game Super Super.

    I'm working in Swift, but I don't think that has anything to do with the issues.

    1. Sprite Kit's playSoundFileNamed method will slowly degrade cpu performance. If you play a few sounds it will be hard to notice, but when playing many sounds very rapidly, it will be more obvious.

    I ended up finding ObjectAL as an awesome sound engine solution to my the Sprite Kit issue.

    2. Changing BitMasks on physicsBodies many times causes a cpu performance degrade. This also doesn't come back as long as the SKScene is not paused. When paused the issue goes away, but it comes back when unpaused. So you don't get the performance back.

    Here is what I was doing...

    func enablePhysics(){
    self.physicsBody?.categoryBitMask = barCategory
    self.physicsBody?.contactTestBitMask = ballCategory | destroyCategory
    self.physicsBody?.collisionBitMask = bottomCategory | borderCategory
    self.physicsBody?.fieldBitMask = field_suckerCategory;
    }
    func disablePhysics(){
    self.name = barCategoryName
    self.physicsBody?.categoryBitMask = 0
    self.physicsBody?.contactTestBitMask = 0
    self.physicsBody?.collisionBitMask = 0
    self.physicsBody?.fieldBitMask = 0
    }

    I was doing this to get around the issue of multiple collisions or collisions after the object was going to remove itself, but was doing remove animation.

    To get around this issue, I put a wasHit flag on the object and set it with the first collision. Then in the collision code, I skip doing anything if the wasHit flag is enabled.

    Word of advice, keep checking for cpu degradation as you work. I was only looking for memory leaks and found my game would get very poor fps when I played it for a while. It was a nightmare to figure out the issue.

    Derrick / Mad Pig
     
  2. Shaun C

    Shaun C Well-Known Member

    Aug 28, 2014
    70
    0
    0
    Ugh... that sound bug in particular sounds like the kind of thing that could have you tearing your hair out.

    Thanks for sharing this info.
     
  3. OnlyJoe

    OnlyJoe Well-Known Member

    Sep 29, 2013
    114
    0
    0
    Auckland
    I am guessing that changing the bits on the physics objects is forcing them to be recalculated in some way, and moved to a different collision group. Might even be recreating the objects each time. Will depend how the engine is optimizing its collision detection.
    In any physics engine there is always going to be a high cost in change an objects collision group.
     

Share This Page