如何在iOS中使用Cocos2d V3制作类似Candy Crush Saga的光线动画应用程序

如何在iOS中使用Cocos2d V3制作类似Candy Crush Saga的光线动画应用程序,ios,cocos2d-iphone,Ios,Cocos2d Iphone,我在iPhone和iPad中使用Cocos2d V3创建了一个类似于Candy Crush Saga的应用程序。我想要糖果上的光线动画。光线应该以不同的方向和距离通过。我已经附上了作为参考的图像 我还有一系列类似光线的动画图像, 有谁能帮我做这件事吗?要找到旋转角度: CGPoint difference = ccpSub(targetCloud.position, sourceCloud.position); CGFloat rotationRadians = ccpToAngle(dif

我在iPhone和iPad中使用Cocos2d V3创建了一个类似于Candy Crush Saga的应用程序。我想要糖果上的光线动画。光线应该以不同的方向和距离通过。我已经附上了作为参考的图像

我还有一系列类似光线的动画图像,


有谁能帮我做这件事吗?

要找到旋转角度:

CGPoint difference = ccpSub(targetCloud.position, sourceCloud.position);
CGFloat rotationRadians = ccpToAngle(difference);
CGFloat rotationDegrees = -CC_RADIANS_TO_DEGREES(rotationRadians);
rotationDegrees -= 90.0f;
CGFloat rotateByDegrees = rotationDegrees - targetCloud.rotation;
要查找比例,请执行以下操作:

float dist = ccpDistance(targetCloud.position,sourceCloud.position);
CCSprite *line = [CCSprite spriteWithImageNamed:@"0_light.png"];
float scale = dist / line.boundingBox.size.width;
要创建动画,请执行以下操作:

-(CCActionSequence *)createRayAnimationFrom:(CGPoint)startPosition atAngle:(float)angle toScale:(float)scale
{
 //Using Texture packer
CCSpriteBatchNode *batchNode = [CCSpriteBatchNode batchNodeWithFile:@"light.pvr.ccz"];
[self addChild:batchNode];


[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"light.plist"];

CCSprite *raySprite = [CCSprite spriteWithSpriteFrameName:@"0_light.png"];
raySprite.position = startPosition;
raySprite.anchorPoint = ccp(0.5, 0.0);

[batchNode addChild:raySprite];

NSMutableArray *animFrames = [NSMutableArray array];
for( int i=1;i<=12;i++)
{
    CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"%d_light.png",i]];
    [animFrames addObject:frame];
}

CCAnimation *animation = [CCAnimation animationWithSpriteFrames:animFrames];
animation.delayPerUnit = 0.1f;
animation.restoreOriginalFrame = YES;


    CCActionAnimate *animAction  = [CCActionAnimate actionWithAnimation:animation];
    CCActionSequence *animSequence = [CCActionSequence actions:[CCActionRotateBy actionWithDuration:0.1 angle:angle],[CCActionScaleBy actionWithDuration:0.1 scaleX:1.0f scaleY:scale],animAction,[CCActionCallBlock actionWithBlock:^{

        [CCActionRemove action];

    }], nil];

[raySprite runAction:animSequence];
 }

为光线创建一个新类,并像本教程那样设置动画:,然后您可以添加更多光线,只需更改角度,这样您就可以面对更多方向感谢Nimisha。这对我来说真的很有用。谢谢!
[self createRayAnimationFrom:sourceCloud atAngle:rotateByDegrees toScale:scale];