I want to be able to improve my game's performance by somehow "flattening" my background nodes.
This youtube video demonstrates how I build up my background graphics.
But, I have my background graphics set up like this.
I use two textures like stamps and repeat then. In this case... one mountain texture with a snowy top... One mountain texture without the snow. I alter the zPosition of these stamps for a "layering" effect.
I then use "fills" which are just SKSpriteNodes of solid grey to layer over parts that need a grey fill.
E.g. Before fill nodes are added
A colour screen with alpha is then added on top to give the mountain a faded looked.
The game sometimes freezes up... but it doesn't freeze when I remove these graphics.
Is there a way to improve performance by merging or flattening my background graphics nodes based on zPosition as a scene is loading up? How would I do this?
Would this improve performance? Or what would be the best way to improve performance in my case?
I think this question is similar... Merge all SKSpriteNode children into a single SKSpriteNode
But, how do I do this in Swift and take zPosition and alpha into account so I don't lose the layering effects?
1 Answers
Answers 1
Somethings you may want to do:
Separate your foreground and background into separate SKS files, and load them into your main SKS file via SKReferenceNode
Convert these SKS files into textures instead of SKReferenceNode
s via code using view.textureFromNode
Ensure your atlas is not being broken up in a way that adds to the draw count
Design your code in a way that not all nodes are on the scene, the more nodes the slower your code becomes.
If you have SKPhysicsBody
's, try to use as few as possible. This can be done my merging multiple bodies together with SKPhysicBody(bodies:)
or creating 1 body with a polygon that goes around multple objects.
Also, if your bodies are not moving via physics (Not by SKAction
s) then make sure that isDynamic
is set to false
If you are running SKAction
s, make sure you use as few of these as possible. For example, if you have 4 different nodes travelling left at 10 points per second, you can put these 4 nodes into a parent node, and run the action on the parent node.
0 comments:
Post a Comment