cocoaTouch/HogHatViewController.m
changeset 3340 96dd168b080b
parent 3339 d558bc5a73c5
child 3352 ac5d14a35482
equal deleted inserted replaced
3339:d558bc5a73c5 3340:96dd168b080b
    26 
    26 
    27     // load all the hat file names and store them into hatArray
    27     // load all the hat file names and store them into hatArray
    28     NSString *hatsDirectory = HATS_DIRECTORY();
    28     NSString *hatsDirectory = HATS_DIRECTORY();
    29     NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:hatsDirectory error:NULL];
    29     NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:hatsDirectory error:NULL];
    30     self.hatArray = array;
    30     self.hatArray = array;
    31     [array release];
    31     
    32 
       
    33     // load all the hat images from the previous array but save only the first sprite and store it in hatSprites
    32     // load all the hat images from the previous array but save only the first sprite and store it in hatSprites
    34     NSMutableArray *spriteArray = [[NSMutableArray alloc] initWithCapacity:[hatArray count]];
    33     NSMutableArray *spriteArray = [[NSMutableArray alloc] initWithCapacity:[hatArray count]];
    35     for (int i=0; i < [hatArray count]; i++) {
    34     for (NSString *hat in hatArray) {
    36         NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@", hatsDirectory,[hatArray objectAtIndex:i]];
    35         NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@", hatsDirectory,hat];
    37         
    36         
    38         UIImage *image = [[UIImage alloc] initWithContentsOfFile: hatFile];
    37         UIImage *image = [[UIImage alloc] initWithContentsOfFile: hatFile];
    39         [hatFile release];
    38         [hatFile release];
    40         CGRect firstSpriteArea = CGRectMake(0, 0, 32, 32);
    39         CGRect firstSpriteArea = CGRectMake(0, 0, 32, 32);
    41         CGImageRef cgImgage = CGImageCreateWithImageInRect([image CGImage], firstSpriteArea);
    40         CGImageRef cgImage = CGImageCreateWithImageInRect([image CGImage], firstSpriteArea);
    42         [image release];
    41         [image release];
    43         
    42         
    44         UIImage *hatSprite = [[UIImage alloc] initWithCGImage:cgImgage];
    43         UIImage *hatSprite = [[UIImage alloc] initWithCGImage:cgImage];
    45         [spriteArray addObject:hatSprite];
    44         [spriteArray addObject:hatSprite];
    46         CGImageRelease(cgImgage);
    45         CGImageRelease(cgImage);
    47         [hatSprite release];
    46         [hatSprite release];
    48     }
    47     }
    49     self.hatSprites = spriteArray;
    48     self.hatSprites = spriteArray;
    50     [spriteArray release];
    49     [spriteArray release];
    51 }
    50 }