Time for action – fixing the hunter movement
The good thing that comes from the fact that physics simulation and rendering are independent is that we can create physics bodies with just a few lines of code without any images, using just the CCNode
class.
In this section, we're going to add the addBoundaries
method, which will add two invisible physics bodies to the sides of the screen so that the hunter doesn't fall off the screen. In addition to this, we're going to adjust the friction of the hunter's physics body so that he doesn't slide too much.
- Open the
PhysicsScene.m
file and add theaddBoundaries
method, as shown in the following code:-(void)addBoundaries { CGSize viewSize = [CCDirector sharedDirector].viewSize; CGRect boundRect = CGRectMake(0, 0, 20, viewSize.height * 0.25f); CCNode *leftBound = [CCNode node]; leftBound.position = ccp(0, _ground.contentSize.height + 30); leftBound.contentSize = boundRect.size;...