Game Development Reference
In-Depth Information
CCMoveBy* move = [CCMoveBy actionWithDuration:duration position:moveTo];
[spiderSprite runAction:move];
}
-(void) update:(ccTime)delta
{
numUpdates++;
if (numUpdates > 50)
{
numUpdates = 0;
// Move at regular speed.
CGPoint moveTo = CGPointMake(CCRANDOM_0_1() * 200-100, ←
CCRANDOM_0_1() * 100-50);
[self moveAway:2 position:moveTo];
}
}
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
// Check if this touch is on the Spider's sprite.
CGPoint touchLocation = [MultiLayerScene locationFromTouch:touch];
BOOL isTouchHandled = CGRectContainsPoint([spiderSprite boundingBox], ←
touchLocation);
if (isTouchHandled)
{
// Reset move counter.
numUpdates = 0;
// Move away from touch loation rapidly.
CGPoint moveTo;
float moveDistance = 40;
float rand = CCRANDOM_0_1();
// Randomly pick one of four corners to move away to.
if (rand < 0.25f)
moveTo = CGPointMake(moveDistance, moveDistance);
else if (rand < 0.5f)
moveTo = CGPointMake(−moveDistance, moveDistance);
Search Nedrilad ::




Custom Search