5

Extract a selection of textures from a Texture Atlas

 3 years ago
source link: https://www.codesd.com/item/extract-a-selection-of-textures-from-a-texture-atlas.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Extract a selection of textures from a Texture Atlas

advertisements

I'm trying to write a method to do the above. My Texture Atlas contains more than 500 Textures. When i store my extracted Textures in a new Array and log its description the Array contains my correct named 3 Textures PLUS all of the Textures the original Atlas contained. Everyone of these is referred to " 'MissingResource.png' (128 x 128)".

My Question is: How can i ONLY store the 3 textures i want in the new Array? Here is the code:

-(void)createSelectedTexturesWith:(NSString*)ImageName;
{
 int bgCount = 1;

 NSMutableString *tempstring = [NSMutableString stringWithString:ImageName];
 SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"textures"];
 NSMutableArray *Leveltextures = [[NSMutableArray alloc]init];

 NSUInteger numImages = atlas.textureNames.count;

for (int i=1;i <= numImages; i++) {
    [tempstring appendFormat:@"_%02d.png",bgCount];
    NSString *textureName = [NSString stringWithString:tempstring];
    SKTexture *temp = [atlas textureNamed:textureName];
    [Leveltextures addObject:temp];
    [tempstring setString:ImageName];
    bgCount++;
}

NSLog(@"Leveltextures Content: %@",[Leveltextures description]);


Not sure I understand what you want. But if I do understand it correctly, why can't you just check if the textureName's prefix matches your imageName and only create the texture and add to the array in that case only ?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK