0
votes

need some advice / pointed in right direction to solve this.. school lad.. not homework!! personal learning. i can't figure out how to get the spites to go from top to bottom. the code below makes them left to right. thanks in advance.

 CCSprite * monster = [CCSprite spriteWithFile:@"image.png"];
// Determine where to spawn the monster along the Y axis
CGSize winSize = [CCDirector sharedDirector].winSize;
int minX = monster.contentSize.width/ 0.2;
int maxX = winSize.height - monster1.contentSize.width/2;
int rangeX = maxX - minX;
int actualX = (arc4random() % rangeX) + minX;

// Create the monster slightly off-screen along the right edge,
// and along a random position along the Y axis as calculated above
monster.position = ccp(winSize1.width + monster.contentSize.width/2, actualX);
[self addChild:monster1];

// Determine speed of the monster
int minDuration = 2.0;
int maxDuration = 4.0;
int rangeDuration = maxDuration - minDuration;
int actualDuration = (arc4random() % rangeDuration) + minDuration;

// Create the actions
CCMoveTo * actionMove = [CCMoveTo actionWithDuration:actualDuration
                                            position:ccp(-monster.contentSize.width/2, actualX)];
CCCallBlockN * actionMoveDone = [CCCallBlockN actionWithBlock:^(CCNode *node) {
    [node removeFromParentAndCleanup:YES];
}];
[monster1 runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];
1

1 Answers

1
votes

The line that says this:

CCMoveTo * actionMove = [CCMoveTo actionWithDuration:actualDuration position:ccp(-monster.contentSize.width/2, actualX)];

Is what is setting up the movement. The position that you are telling the sprite to move to, ccp(-monster.contentSize.width/2, actualX), is an (X, Y) coordinate of where you would like to move to. X being the first value, and Y being the second value. For some reason you have actualX in the Y value of where you would like to move to.

If you want to move up or down, you should be moving the sprite to a new Y coordinate. Perhaps something like this?

CCMoveTo * actionMove = [CCMoveTo actionWithDuration:actualDuration position:ccp(monster.position.x, monster.position.y - 300)];