需要一些建议/指出正确的方向来解决这个问题..学校小伙子..不是家庭作业!个人学习。我不知道如何让怨恨从上到下。下面的代码使它们从左到右。提前致谢。
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]];