Game Development Reference
In-Depth Information
Figure 7-4 . The background stripes are moving, but they're also leaving the screen forever
Note You'll also notice that Figure 7-4 doesn't look at all like Figure 7-1 or the
game project. Figure 7-4 uses dummy graphics to better illustrate the parallax
images “leaving” the screen. It's much harder to see with the star background
stripes. You'll notice this effect much better in motion. What you can see in the
image is that the individual stripes have moved at different rates, which is what
parallax scrolling is all about.
Listing 7-2 shows that the code to make the background scroll is surprisingly simple if
you ignore for a moment the flaw seen in Figure 7-4 .
Listing 7-2. Moving the Background Stripes
-(void) update:(ccTime)delta
for (CCSprite* sprite in spriteBatch.children)
CGPoint pos = sprite.position;
pos.x - = (scrollSpeed + sprite.zOrder) * (delta * 20);
sprite.position = pos;
Search Nedrilad ::

Custom Search