Created
May 2, 2013 20:37
-
-
Save oliverbarreto/5505224 to your computer and use it in GitHub Desktop.
ObjectiveC CA Load image and with sprites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *path = [[NSBundle mainBundle] pathForResource:@"yourImage.png" ofType:nil]; | |
CGImageRef img = [UIImage imageWithContentsOfFile:path].CGImage; | |
CALayer *layer = [CALayer layer]; | |
layer.contents = (id)img; | |
layer.bounds = CGRectMake( 0, 0, CGImageGetWidth(img), CGImageGetHeight(img) ); | |
// with sprites atlasses | |
CALayer *layer = [CALayer layer]; | |
layer.contents = (id)img; | |
CGSize size = CGSizeMake( 160, 198 ); // size in pixels of one frame | |
CGSize normalizedSize = CGSizeMake( size.width/CGImageGetWidth(img), size.height/CGImageGetHeight(img) ); | |
layer.bounds = CGRectMake( 0, 0, size.width, size.height ); | |
layer.contentsRect = CGRectMake( 0, 0, normalizedSize.width, normalizedSize.height ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment