Sprite Kit 辅助工具、扩展和实用工具。
最佳和最简单的方法是使用 CocoaPods。
pod 'ISSpriteKit'
高度可定制的节点,可模拟视差滚动。
#import "MyScene.h"
#import "ISParallaxNode.h"
@interface MyScene ()
@property (strong, nonatomic) ISParallaxNode *parallaxNode;
@end
@implementation MyScene
- (id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
self.parallaxNode = [[ISParallaxNode alloc] initWithImageNamed:@"Horizontal" direction:ISScrollDirectionLeft];
[self addChild: self.parallaxNode];
}
return self;
}
- (void)update:(NSTimeInterval)currentTime {
[self.parallaxNode update:currentTime];
}
@end
ISParallaxLayer 可以包含多个 ISParallaxNodes。
#import "MyScene.h"
#import "ISParallaxLayer.h"
#import "ISParallaxNode.h"
@interface MyScene ()
@property (strong, nonatomic) ISParallaxLayer *parallaxLayer;
@end
@implementation MyScene
- (id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
self.parallaxLayer = [ISParallaxLayer node];
ISParallaxNode *parallaxNodeRightDirection = [[ISParallaxNode alloc] initWithImageNamed:@"Horizontal"
direction:ISScrollDirectionRight];
[self.parallaxLayer addParallaxNode:parallaxNodeRightDirection];
ISParallaxNode *parallaxNodeLeftDirection = [[ISParallaxNode alloc] initWithImageNamed:@"Horizontal"
direction:ISScrollDirectionLeft];
parallaxNodeLeftDirection.position = CGPointMake(0, self.frame.size.height / 2);
[self.parallaxLayer addParallaxNode:parallaxNodeLeftDirection];
[self addChild:self.parallaxLayer];
}
return self;
}
- (void)update:(NSTimeInterval)currentTime {
[self.parallaxLayer update:currentTime];
}
@end
查看示例项目以获取更多详情。
ISSpriteKit 在 MIT 许可协议 下授权。