【问题标题】:How to make Ray Animation like Candy Crush Saga application using Cocos2d V3 in iOS如何在 iOS 中使用 Cocos2d V3 制作像 Candy Crush Saga 一样的 Ray Animation
【发布时间】:2014-05-20 14:38:24
【问题描述】:

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

我也有射线之类的动画图像序列,

谁能帮助我如何做到这一点?

【问题讨论】:

  • 为射线创建一个新类并像本教程一样对其进行动画处理:makegameswith.us/gamernews/331/…,然后您可以通过改变角度添加更多射线,这样您就可以面向更多方向

标签: ios cocos2d-iphone


【解决方案1】:

求旋转角度:

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];

【讨论】:

  • 谢谢尼米莎。它真的对我有用。非常感谢!
猜你喜欢
  • 2014-03-18
  • 2013-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-09
  • 2012-11-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多