0
我使用Cocos2d V3在iPhone和iPad上創建了類似於Candy Crush Saga應用程序的應用程序。我想要糖果上的射線動畫。射線應該通過不同的方向和不同的距離。我附上了圖片以供參考。如何使iOS中使用Cocos2d V3的Candy Crush Saga應用程序生成Ray動畫
我也有像光線動畫圖像序列,
可以在任何一個可以幫助我如何可以做到這一點?
我使用Cocos2d V3在iPhone和iPad上創建了類似於Candy Crush Saga應用程序的應用程序。我想要糖果上的射線動畫。射線應該通過不同的方向和不同的距離。我附上了圖片以供參考。如何使iOS中使用Cocos2d V3的Candy Crush Saga應用程序生成Ray動畫
我也有像光線動畫圖像序列,
可以在任何一個可以幫助我如何可以做到這一點?
爲了找到旋轉角度:
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];
}
你要調用此函數每個目標雲:
[self createRayAnimationFrom:sourceCloud atAngle:rotateByDegrees toScale:scale];
謝謝Nimisha。它真的適合我。非常感謝 ! – Sujal
爲Ray創建一個新類並使其具有本教程的動畫效果:https://www.makegameswith.us/gamernews/331/ccanimatedsprite-the-easiest-way-to-animate-a-spr,然後您可以添加更多的光線只是改變角度,所以你可以面對更多的方向 – mursang