Falling CCSprites
- by Coder404
Im trying to make ccsprites fall from the top of the screen. Im planning to use a touch delegate to determine when they fall. How could I make CCSprites fall from the screen in a way like this:
-(void)addTarget {
Monster *target = nil;
if ((arc4random() % 2) == 0) {
target = [WeakAndFastMonster monster];
} else {
target = [StrongAndSlowMonster monster];
}
// Determine where to spawn the target along the Y axis
CGSize winSize = [[CCDirector sharedDirector] winSize];
int minY = target.contentSize.height/2;
int maxY = winSize.height - target.contentSize.height/2;
int rangeY = maxY - minY;
int actualY = (arc4random() % rangeY) + minY;
// Create the target slightly off-screen along the right edge,
// and along a random position along the Y axis as calculated above
target.position = ccp(winSize.width + (target.contentSize.width/2), actualY);
[self addChild:target z:1];
// Determine speed of the target
int minDuration = target.minMoveDuration; //2.0;
int maxDuration = target.maxMoveDuration; //4.0;
int rangeDuration = maxDuration - minDuration;
int actualDuration = (arc4random() % rangeDuration) + minDuration;
// Create the actions
id actionMove = [CCMoveTo actionWithDuration:actualDuration position:ccp(-target.contentSize.width/2, actualY)];
id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)];
[target runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];
// Add to targets array
target.tag = 1;
[_targets addObject:target];
}
This code makes CCSprites move from the right side of the screen to the left. How could I change this to make the CCSprites to move from the top of the screen to the bottom?