Game Development Reference
In-Depth Information
}
}
CGPoint offset = (_softBodyPlayer ?
_playerNode.parent.positionInPoints
: CGPointZero);
[self scrollToTarget:_playerNode withOffset:offset];
}
If the
_softBodyPlayer
flag is set, instead of the force being applied to the
_play-
erNode
, it is applied to all nodes. Remember that
_playerNode
is the center node in
the
PlayerSoftBody.ccb
, so its children are the soft-body player's physics-enabled nodes.
And each one is now accelerated instead of the
_playerNode
.
Note
It may be worth a try at a later time to apply the force only on the
_playerNode
(center node) or to spread the force unevenly—for instance,
applying the force only on the circumference bodies and not on the center body.
Each approach will result in different movement behavior, and you are welcome
to experiment.
The
scrollToTarget:
method is called with the
_playerNode
's parent position as
offset
, just like in
Listing 10-5
before.
Before you can compile this code without errors, you'll have to update the
scrollToTarget:
method. Apply the changes highlighted in
Listing 10-7
.
It's not
much, you just need to add the
withOffset:(CGPoint)offset
parameter and add
the offset to
target.positionInPoints
in the line where
viewPos
is assigned.
The rest of the method is omitted for brevity. You should not remove the remainder of the
method; rather, leave it unchanged.
Listing 10-7
.
Adding the offset parameter to the scrollToTarget: method
-(void) scrollToTarget:(CCNode*)target
withOffset:(CGPoint)offset
{
CGSize viewSize = [CCDirector sharedDirector].viewSize;
CGPoint viewCenter = CGPointMake(viewSize.width / 2.0,
viewSize.height / 2.0);
Search WWH ::
Custom Search