Game Development Reference
In-Depth Information
joystick.isDPad = YES;
joystick.numberOfDirections = 8;
The dead zone properties can be removed—they're not needed for a digital controller.
The joystick is set to digital controls by setting the isDPad property to YES .
You can also define the number of directions. While D-pads regularly have four direc-
tions, in many games you can keep two directions pressed at the same time to have the
character move in a diagonal direction. To achieve the same effect, set the number-
OfDirections property to 8. SneakyJoystick automatically ensures that these
directions are evenly divided onto the thumbpad controller. Of course, you'll get
strange results if you set the number of directions to 6, but then again, maybe that's ex-
actly what you need to travel across a hexagonal tile map.
In this chapter you learned several tricks to make an effective parallax scrolling back-
ground. Not only can you scroll the background infinitely and without flickering edges,
you also learned how to properly separate the parallax layers so TexturePacker can cut
down on unnecessary transparent areas while keeping the image's offset so you don't
have to fumble with positioning the parallax layers.
The second half of this chapter introduced you to SneakyInput, an open source project
to add virtual thumbsticks and buttons to any cocos2d game. It may not be perfect, as it
needs a few tweaks to work with ARC and the latest cocos2d 2.0 version—unless
you're using Kobold2D, of course—but it's good enough for most games, and it defin-
itely beats writing your own virtual thumbstick code.
The ship is now controllable with a virtual joypad and stays within the screen's bound-
aries while moving, and it's able to shoot with the press of a button—but the game is
still lacking something. A shoot-'em-up isn't a shoot-'em-up without something to
shoot down, is it? The next chapter addresses that issue.
Search Nedrilad ::

Custom Search