我正在使用下面的代码动画一片叶子,同时将它从屏幕顶部拖到底部。我希望从随机位置开始有多个实例。什么是最好的方式呢?
leaf1Sprite = [CCSprite spriteWithFile:@"LeafBrown0000.png"];
leaf1Sprite.position = ccp(screenSize.width * 0.5f - 40.0f, screenSize.height);
leaf1Sprite.contentSize = CGSizeMake([leaf1Sprite boundingBox].size.width, [leaf1Sprite boundingBox].size.height);
[self addChild:leaf1Sprite z:10 tag:30];
CCAnimation *leaf1Ani = [CCAnimation animation];
[leaf1Ani addFrameWithFilename:@"LeafBrown0000.png"];
[leaf1Ani addFrameWithFilename:@"LeafBrown0001.png"];
[leaf1Ani addFrameWithFilename:@"LeafBrown0002.png"];
[leaf1Ani addFrameWithFilename:@"LeafBrown0003.png"];
[leaf1Ani addFrameWithFilename:@"LeafBrown0004.png"];
[leaf1Ani addFrameWithFilename:@"LeafBrown0005.png"];
[leaf1Ani addFrameWithFilename:@"LeafBrown0006.png"];
[leaf1Ani addFrameWithFilename:@"LeafBrown0007.png"];
[leaf1Ani addFrameWithFilename:@"LeafBrown0008.png"];
[leaf1Ani addFrameWithFilename:@"LeafBrown0009.png"];
[leaf1Ani addFrameWithFilename:@"LeafBrown0010.png"];
[leaf1Ani addFrameWithFilename:@"LeafBrown0011.png"];
[leaf1Ani addFrameWithFilename:@"LeafBrown0012.png"];
[leaf1Ani addFrameWithFilename:@"LeafBrown0013.png"];
[leaf1Ani addFrameWithFilename:@"LeafBrown0014.png"];
[leaf1Ani addFrameWithFilename:@"LeafBrown0015.png"];
[leaf1Ani addFrameWithFilename:@"LeafBrown0016.png"];
[leaf1Ani addFrameWithFilename:@"LeafBrown0017.png"];
[leaf1Ani addFrameWithFilename:@"LeafBrown0018.png"];
[leaf1Ani addFrameWithFilename:@"LeafBrown0019.png"];
id leaf1AniANIMATION = [CCAnimate actionWithDuration:1.9f animation:leaf1Ani restoreOriginalFrame:YES];
id repeatLeaf1Animation = [CCRepeatForever actionWithAction:leaf1AniANIMATION];
[leaf1Sprite runAction:repeatLeaf1Animation];
[leaf1Sprite runAction:[CCMoveTo actionWithDuration:5.0f position:ccp(screenSize.width * 0.5f + 10.0f, -100.0f)]];
答案 0 :(得分:2)
在屏幕上随机定位:
float screenWidth = screenSize.width * 0.5f;
randomX = arc4random() % (int)screenWidth;
答案 1 :(得分:1)
查看粒子系统样本。特别是有一个名为“Rain”的东西,与你所要求的类似。我没有在粒子系统中完成动画;希望这是可能的。