should I cache textures in properties in sprite kit?

為{幸葍}努か 提交于 2019-12-04 06:43:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!