Game Development Reference
In-Depth Information
numUpdates = 0;
[spiderSprite stopAllActions];
// Let the Spider move randomly.
CGPoint moveTo = CGPointMake(CCRANDOM_0_1() * 200-100, ←
CCRANDOM_0_1() * 100-50);
CCMoveBy* move = [CCMoveBy actionWithDuration:1 position:moveTo];
[spiderSprite runAction:move];
The Spider class now uses its own game logic to move the spiders around on the
screen. Granted, it won't win any prizes at this year's Artificial Intelligence Symposi-
um; it's just meant as an example.
Up to this point you know you can receive touch input using CCLayer nodes, but in
fact any class can receive touch input by using the CCTouchDispatcher class dir-
ectly. Your class only needs to implement either the CCStandardTouchDelegate
or CCTargetedTouchDelegate protocol. You add the appropriate protocol defini-
tion in angle brackets following the parent class in the @interface definition, as
shown in Listing 5-13 .
Listing 5-13. The CCTargetedTouchDelegate Protocol
@interface Spider : CCNode < CCTargetedTouchDelegate>
The implementation in Listing 5-14 highlights the changes made to the Spider class.
The Spider class now reacts to targeted touch input. Whenever you tap a spider, it
quickly moves away from your finger. (Contrary to common perceptions, spiders are
usually more afraid of humans than the other way around, exceptions notwithstanding.)
Search Nedrilad ::

Custom Search