Game Development Reference
In-Depth Information
CGSize screenSize = [CCDirector sharedDirector].winSize;
if (pos.x < −screenSize.width)
pos.x + = screenSize.width * 2;
sprite.position = pos;
The stripes' x position now only needs to be checked if it's less than negative screen
width and, if it is, multiplied by twice the screen width. Essentially, this moves the
sprite that has just left the screen on the left side to the right side, just outside the
screen. This repeats forever with the same two sprites, giving the effect of endless
Tip Notice that the background of the screen scrolls, but the ship stays in
place. Inexperienced game developers often have the misconception that
everything on the screen needs to be scrolling to achieve the effect of game ob-
jects passing by the player character as he progresses through the game world.
Instead, you can much more easily create the illusion of objects moving on the
screen by moving the background layers but keeping the player character fixed
in place. Popular examples of games that make use of this visual illusion are
Super Turbo Action Pig, Canabalt, Super Blast, DoodleJump, and Zombieville
USA. Typically, the game objects scrolling into view are randomly generated
shortly before they appear, and when they leave the screen they're removed
from the game. Chapter 11 makes use of the same effect where the player char-
acter remains in the center of the screen while only the game world underneath
the player is actually moving, giving the impression that the player moves
around in the world.
Fixing the Flicker
So far, so good. Only one issue remains. If you look closely, you'll notice a vertical,
flickering line appearing where the two background stripes meet. That's where they
align with each other. This line appears because of rounding errors in their positions in
Search Nedrilad ::

Custom Search