Game Development Reference
In-Depth Information
CGSize screenSize = [CCDirector sharedDirector].winSize;
ParallaxBackground* background = [ParallaxBackground node];
[self addChild:background z:-1];
/*
// add a background image
CCSprite* background = [CCSprite spriteWithSpriteFrameName:@"background.png"];
background.position = CGPointMake(screenSize.width / 2, screenSize.height / 2);
[self addChild:background];
*/
...
You also need to import the ParallaxBackground.h header file at the top of the
GameLayer.m file:
#import "ParallaxBackground.h"
The parallax background replaces the CCLayerColor and the background CCS-
prite , which were placeholders from Chapter 6 , so you also want to remove or com-
ment out any reference to the background sprite or CCLayerColor . In addition, I set
the OpenGL clear color to white—later this will help you see a visual artifact that oc-
curs in the early versions of the parallax scrolling code.
Moving the ParallaxBackground
In the ScrollingWithJoy01 project, I also added a quick-and-dirty scrolling of the back-
ground stripes. It does show a parallax effect, although the images quickly leave the
screen, revealing the blank background behind them. Figure 7-4 isn't exactly what I
had in mind, but I'm getting there.
 
Search Nedrilad ::




Custom Search