Game Development Reference
In-Depth Information
- (id)initWithBackgrounds:(NSArray *)imageFiles
size:(CGSize)size
speed:(CGFloat)velocity
{
if (self = [super init])
{
self.velocity = velocity;
self.noOfBackgrounds = [imageFiles count];
self.backgrounds =
[NSMutableArray
arrayWithCapacity:self.noOfBackgrounds];
}];
}
return self;
}
7. Using the imageFiles , enumerate them using the block. In enumeration, add
background nodes using the imageFiles class, add them to the backgrounds
array and on FSParallaxNode .
[imageFiles enumerateObjectsUsingBlock:^(id
obj, NSUInteger idx, BOOL *stop)
{
SKSpriteNode *backgroundNode =
[SKSpriteNode
spriteNodeWithImageNamed:obj];
[self.backgrounds
addObject:backgroundNode];
[self addChild:backgroundNode];
}];
8. Also, specify the backgroundNode size, which is passed in the init method,
its anchorPoint to CGPointZero , its position according to the idx integer
and a name of the node as background .
backgroundNode.size = size;
backgroundNode.anchorPoint = CGPointZero;
backgroundNode.position =
Search WWH ::




Custom Search