Game Development Reference
In-Depth Information
5. Now we need to add two methods in the header of
FSParallaxNode
. Firstly,
in the
init
method, we need to specify
imageFiles
, which are the images to
be scrolled, the canvas size, and the velocity with which the images will scroll.
- (id)initWithBackgrounds:(NSArray *)imageFiles
size:(CGSize)size
speed:(CGFloat)velocity;
Secondly, an update method called from the update of Scene in which the
FSParallaxNode
method is added so that the scrolling is made infinite.
- (void)updateForDeltaTime:(NSTimeInterval)diffTime;
6. In
FSParallaxNode.m
, declare some properties in its private interface to store
all background nodes, counts of backgrounds, and velocity of that parallax node.
@property (nonatomic, strong) NSMutableArray*
backgrounds;
@property (nonatomic, assign) NSInteger
noOfBackgrounds;
@property (nonatomic, assign) CGFloat
velocity;
In definition of the
init
method, first assign all the parameters passed in the
function like
velocity
. Now we assign
noOfBackgrounds
using the
im-
ageFiles
count and make an array of backgrounds with a capacity of
noOfBackgrounds
.