Created
October 27, 2016 10:34
-
-
Save kingnight/67fac50155e53664789ce3e922ef77b5 to your computer and use it in GitHub Desktop.
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
- (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 contentsRect | |
layer.contentsRect = rect; | |
} | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
//load sprite sheet | |
UIImage *image = [UIImage imageNamed:@"Sprites.png"]; | |
//set igloo sprite | |
[self addSpriteImage:image | |
withContentRect:CGRectMake(0, 0, 0.5, 0.5) | |
toLayer:self.iglooView.layer]; | |
//set cone sprite | |
[self addSpriteImage:image | |
withContentRect:CGRectMake(0.5, 0, 0.5, 0.5) | |
toLayer:self.coneView.layer]; | |
//set anchor sprite | |
[self addSpriteImage:image | |
withContentRect:CGRectMake(0, 0.5, 0.5, 0.5) | |
toLayer:self.anchorView.layer]; | |
//set spaceship sprite | |
[self addSpriteImage:image | |
withContentRect:CGRectMake(0.5, 0.5, 0.5, 0.5) | |
toLayer:self.shipView.layer]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment