我正在为我的游戏中的图像资产使用地图集。我在我的游戏场景开始时预加载了我所有的地图集,SKTextureAtlas preloadTextureAtlases
这在我开始使用它时产生了很大的不同。这是我的问题:
我是否应该为每个将一次又一次地应用于生成的怪物或拾取精灵的纹理创建一个属性?还是因为我在我的游戏场景中预加载了我的地图集,所以它完全没有必要的开销?
下面是 Monster 类中的 2 个非常简单的示例。
缓存纹理:
- (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;
}
不要缓存纹理。
- (Monster *)monster
{
SKTextureAtlas * atlas = [SKTextureAtlas atlasNamed:monsterAtlas];
Monster * monster = [Monster spriteNodeWithTexture:[atlas textureNamed:@"monster-fighter"]];
return monster;
}