Game Development Reference
In-Depth Information
fireButton.radius = buttonRadius;
fireButton.position = CGPointMake(screenSize.width - buttonRadius, buttonRadius);
[self addChild:fireButton];
}
SneakyButton doesn't use the CGRect parameter of the button's initWithRect
method, which is why you're simply passing CGRectZero . The actual touch code
uses the radius property to determine whether the button should react to the touch.
The button in this case should be neatly tucked into the lower right-hand corner. Sub-
tracting the buttonRadius from the screen width and setting its height to but-
tonRadius places it exactly at the desired location.
Tip The use of the buttonRadius variable lets you change the radius of the
button in one place. Otherwise, you'd have to update several values in several
places. This is not only extra work for a value you might want to tweak several
times before you get it exactly the way you want, but it can also introduce
subtle bugs, because you're a human and you tend to forget things, such as
changing that one value over there. Suddenly the button is offset—or worse, the
input doesn't match the button's location.
The InputLayer class also schedules the update method. For now, the update
method is used only to log whether the fire button was touched:
-(void) update:(ccTime)delta
{
if (fireButton.active)
{
CCLOG(@"FIRE!!!");
}
}
Instead of shooting a bullet, keep things simple for now and simply log a successful
button press. If you try the ScrollingWithJoy03 project now, you'll notice that
there isn't any button drawn. Yet when you touch the screen at the lower right-hand
corner, you'll see the “FIRE!!!” message appear in the Debugger Console window. So,
all is well and right, except that the button can't be seen—which you need to fix.
Search Nedrilad ::




Custom Search