Game Development Reference
In-Depth Information
CGPointMake(size.width * idx, 0.0);
backgroundNode.name = @"background";
After all this, our
init
method is ready as shown in the following screenshot:
Now let's see how these backgrounds added on
FSParallaxNode
are to be scrolled; it
will be done by an instance update method.
1. Some
cleanUp
has to be done or in other terms some code movement. Copy the
two static methods used in the
FSMyScene
to
FSParallaxNode
class used
for some math, remove the initialization of the
SpaceBackground
method and
the call of moving background made in the update from
FSMyScene
. Cut the
code of the method for moving the background from the
FSMyScene
file and
paste in the
updateForDeltaTime
function of
FSParallaxNode
. Now we
will be making some tweaks to the method.
2.
SKParallax
node is the parent for all the other nodes of backgrounds added on
it. So using the velocity, send in the
init
and
diffTime
, method which will be
passed by the
FSMyScene
update methods, we calculate the position of the par-
ent that is,
FSParallax
node.
- (void)updateForDeltaTime:(NSTimeInterval)diffTime
{
CGPoint bgVelocity = CGPointMake(self.velocity,
0.0);
CGPoint amtToMove =
CGPointMultiplyScalar(bgVelocity,diffTime);
self.position = CGPointAdd(self.position,