Game Development Reference
In-Depth Information
if ((self = [super init]))
[self addFireButton];
[self addJoystick];
[self scheduleUpdate];
return self;
Tip Gray areas are useful! I mean gray images like joystick-back.png .
By using just grayscale colors, you can colorize (tint) the image using the col-
or property of the sprite. You can create red, green, yellow, blue, magenta, and
other colored versions of the same image, saving both download size and in-
game memory. The only drawback is that its's a flat color, so instead of shades
of gray, your image uses shades of red. This trick works best with images that
are supposed to be shades of a single color.
You want the thumbstick on the screen to be used to control the ship, of course. As
usual, the update method processes the input, as shown in Listing 7-14 . You can add
the changes at the end of the method.
Listing 7-14. Moving the Ship Based on Joystick Input
-(void) update:(ccTime)delta
// Velocity must be scaled up by a factor that feels right
CGPoint velocity = ccpMult(joystick.velocity, 7000 * delta);
ship.position = CGPointMake(ship.position.x + velocity.x * delta,←
ship.position.y + velocity.y * delta);
You use the velocity property of the joystick to change the ship's position, but not
without scaling it up. The velocity values are a tiny fraction of a pixel, so you need
to multiply the velocity using cocos2d's ccpMult method, which takes a CGPoint
Search Nedrilad ::

Custom Search