I have a game with 4 Texture Atlases. Each atlas is 4096 x 4096 and contains roughly 300 sprites, all ~ 15kb - 50kb. Unoptimised in Texture Packer, they're around 2 - 4MB each, and about half that when optimised.
They contain assets to draw characters, but I'm finding it's very slow to draw a single character (around 24 nodes) ~ 0.5 seconds. This is because of multiple calls to [atlas textureNamed:textureName]
To speed things up, I want to preload the atlases. Ideally I would keep them in memory as I always need them. So my first question is, is this possible with atlases of this size? I've tried calling [SKTextureAtlas preloadTextureAtlases:@[MaleFeatureAtlas] withCompletionHandler...]
but I get a crash with no stack trace, just a lost connection to device.
Currently, I have an AtlasManager class, that has static variables that initialise to each texture atlas:
static SKTextureAtlas *MaleFeatureAtlas;
static SKTextureAtlas *MaleItemAtlas;
static SKTextureAtlas *FemaleFeatureAtlas;
static SKTextureAtlas *FemaleItemAtlas;
@implementation AtlasManager
{
}
#pragma mark - Initialisation Methods
+ (void)initialize
{
MaleFeatureAtlas = [SKTextureAtlas atlasNamed:MaleFeatures];
MaleItemAtlas = [SKTextureAtlas atlasNamed:MaleItems];
FemaleFeatureAtlas = [SKTextureAtlas atlasNamed:FemaleFeatures];
FemaleItemAtlas = [SKTextureAtlas atlasNamed:FemaleItems];
}
Each character sprite has an instance of an AtlasManager, but since the SKTextureAtlases are static variables, I figured they would be fast to draw. But the constant calls to [atlas textureNamed:textureName]
really slow the drawing down. I am storing an NSDictionary of nodes once drawn, so redrawing is very quick, but the initial draw takes far too long. Rendering 8 characters, with just over 100 nodes in total, takes about 5 seconds.
So, is a singleton approach better than using static variables? And is it wise to preload atlases of this size?