问题
I am using atlases for the image assets in my game. I am preloading all my atlases at the beginning of my Game Scene with SKTextureAtlas preloadTextureAtlases
which made a big difference when I started using it. Here is my question:
Should I create a property for each texture that is going to be applied again and again to spawned monster or pickup sprites? Or is it completely unnecessary overhead because I am preloading my atlases in my Game Scene?
The below are 2 very simple examples in a Monster class.
Cache Texture:
- (id)initWithSize:(CGSize)size
{
if (self = [super init]) {
SKTextureAtlas * atlas = [SKTextureAtlas atlasNamed:monsterAtlas];
self.monsterFighterTexture = [atlas textureNamed:@"monster-fighter"];
}
return self;
}
- (Monster *)monster
{
Monster * monster = [Monster spriteNodeWithTexture:self.monsterFighterTexture];
return monster;
}
Don't cache texture.
- (Monster *)monster
{
SKTextureAtlas * atlas = [SKTextureAtlas atlasNamed:monsterAtlas];
Monster * monster = [Monster spriteNodeWithTexture:[atlas textureNamed:@"monster-fighter"]];
return monster;
}
来源:https://stackoverflow.com/questions/28007839/should-i-cache-textures-in-properties-in-sprite-kit