To simulate that the Yeti is running for its life, we will scroll the background, the floors, and the platforms independently.
To do this, let's start by defining a constant that we will use to control the speed of the blocks:
// Value for the blocks speed const float kBLOCKS_SPEED = 220.0f;
Now we call the method that will start everything by adding the following lines at the end of the init
method just before return self;
:
// Make the yeti run [self makeYetiRun];
We implement it by adding the following block of code:
-(void) makeYetiRun{ // Run action [_yeti.yetiSprite runAction:_yeti.actionRun]; // Update state _yeti.yetiState = yetiRunning; // Move platforms [self movePlatforms]; // Move floors [self moveFloors]; // Run the scrolling action if ([_backGroundScrollingNode numberOfRunningActions] == 0) { [_backGroundScrollingNode runAction:_loop]; } }
In this method, we start the previously...