/ Published in: Objective C
Very simple use of an non-animating spritesheet for iOS
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
-(void) addSpriteImage:(UIImage *) image withContentRect:(CGRect) rect toLayer:(CALayer *) layer { //set image layer.contents = (__bridge id)image.CGImage; //scale contents to fit layer.contentsGravity = kCAGravityResizeAspect; //set contentRect to appropriate place in image layer.contentsRect = rect; } - (void)viewDidLoad { [super viewDidLoad]; UIImage *image = [UIImage imageNamed:@"spritesheet.png"]; [self addSpriteImage:image withContentRect:CGRectMake(0, 0, 0.5, 0.5) toLayer:self.someUIView.layer]; [self addSpriteImage:image withContentRect:CGRectMake(0.5, 0, 0.5, 0.5) toLayer:self.someUIView.layer]; [self addSpriteImage:image withContentRect:CGRectMake(0, 0.5, 0.5, 0.5) toLayer:self.someUIView.layer]; [self addSpriteImage:image withContentRect:CGRectMake(0.5, 0, 0.5, 0.5) toLayer:self.someUIView.layer]; }