★ TouchArcade needs your help. Click here to support us on Patreon.

Some issues in Sprite Kit I've found.

11-29-2014, 07:42 PM
#1
Some issues in Sprite Kit I've found.

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

Games from the crazy pig:
www.madpiggames.com
11-29-2014, 11:56 PM
#2
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.
11-30-2014, 06:29 AM
#3
Joined: Sep 2013
Location: Auckland
Posts: 114
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.