cocoaTouch/HogHatViewController.m
changeset 3352 ac5d14a35482
parent 3340 96dd168b080b
child 3357 3836a31879e7
equal deleted inserted replaced
3351:3fd3f116f2fc 3352:ac5d14a35482
     6 //  Copyright 2010 __MyCompanyName__. All rights reserved.
     6 //  Copyright 2010 __MyCompanyName__. All rights reserved.
     7 //
     7 //
     8 
     8 
     9 #import "HogHatViewController.h"
     9 #import "HogHatViewController.h"
    10 #import "CommodityFunctions.h"
    10 #import "CommodityFunctions.h"
    11 
    11 #import "UIImageExtra.h"
    12 
    12 
    13 @implementation HogHatViewController
    13 @implementation HogHatViewController
    14 @synthesize teamDictionary, hatArray, hatSprites, lastIndexPath, selectedHog;
    14 @synthesize teamDictionary, hatArray, hatSprites, lastIndexPath, selectedHog;
    15 
    15 
    16 
    16 
    31     
    31     
    32     // 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
    33     NSMutableArray *spriteArray = [[NSMutableArray alloc] initWithCapacity:[hatArray count]];
    33     NSMutableArray *spriteArray = [[NSMutableArray alloc] initWithCapacity:[hatArray count]];
    34     for (NSString *hat in hatArray) {
    34     for (NSString *hat in hatArray) {
    35         NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@", hatsDirectory,hat];
    35         NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@", hatsDirectory,hat];
    36         
    36         UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile: hatFile andCutAt:CGRectMake(0, 0, 32, 32)];
    37         UIImage *image = [[UIImage alloc] initWithContentsOfFile: hatFile];
       
    38         [hatFile release];
    37         [hatFile release];
    39         CGRect firstSpriteArea = CGRectMake(0, 0, 32, 32);
       
    40         CGImageRef cgImage = CGImageCreateWithImageInRect([image CGImage], firstSpriteArea);
       
    41         [image release];
       
    42         
       
    43         UIImage *hatSprite = [[UIImage alloc] initWithCGImage:cgImage];
       
    44         [spriteArray addObject:hatSprite];
    38         [spriteArray addObject:hatSprite];
    45         CGImageRelease(cgImage);
       
    46         [hatSprite release];
    39         [hatSprite release];
    47     }
    40     }
    48     self.hatSprites = spriteArray;
    41     self.hatSprites = spriteArray;
    49     [spriteArray release];
    42     [spriteArray release];
    50 }
    43 }