Falling CCSprites

Posted by Coder404 on Game Development See other posts from Game Development or by Coder404
Published on 2012-07-07T12:32:53Z Indexed on 2012/07/07 15:23 UTC
Read the original article Hit count: 254

Filed under:
|
|
|

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?

© Game Development or respective owner

Related posts about cocos2d-iphone

Related posts about ios