2013-11-21 37 views
0

我正試圖編寫一個方法來完成上述操作。我的紋理圖集包含超過500個紋理。當我將提取的紋理存儲在新的陣列中並記錄其描述時,陣列包含我正確命名的3個紋理加上原始Atlas包含的所有紋理。所有這些都被稱爲「'MissingResource.png'(128 x 128)」。從紋理地圖提取紋理選擇

我的問題是:如何只存儲我想要在新的數組中的3個紋理?下面是代碼:

-(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]); 

}

回答

0

不知道我理解你想要什麼。但是,如果我確實瞭解它,爲什麼不能檢查textureName的前綴是否與imageName匹配,並且僅在此情況下僅創建紋理並添加到數組中?

0

謝謝你原型,這對我來說。雖然代碼可能不太優雅,但在這裏。也許它可以幫助別人。

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

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

    for (NSString *string in atlasArray) { 

     if ([string hasPrefix:ImageName]){ 

     [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]); 

}