Có thể trong Cocos2d để tạo hoạt ảnh di chuyển có thể đi trên một con đường cụ thể không?Cocos2d di chuyển hình ảnh động trên đường dẫn
Ví dụ: tôi nên làm gì nếu tôi cần một đối tượng di chuyển trên vòng cung hoặc vòng tròn đầy đủ?
Trân trọng!
Có thể trong Cocos2d để tạo hoạt ảnh di chuyển có thể đi trên một con đường cụ thể không?Cocos2d di chuyển hình ảnh động trên đường dẫn
Ví dụ: tôi nên làm gì nếu tôi cần một đối tượng di chuyển trên vòng cung hoặc vòng tròn đầy đủ?
Trân trọng!
Chắc chắn bạn có thể làm điều này bằng:
ccBezierConfig bezier;
bezier.controlPoint_1 = ccp(320,0); // control point 1
bezier.controlPoint_2 =ccp(0,0); // control point 2
bezier.endPosition = ccp(endPoint.x,endPoint.y) ;
id bezierForward = [CCBezierTo actionWithDuration:3 bezier:bezier];
[ball runAction:bezierForward];
bạn có thể sử dụng ccBezier để di chuyển bất kỳ nút trong đường cong:
Bây giờ Animation Phần:
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"eggAnimation.plist"];
spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"eggAnimation.png"];
[gameBackgroundLayer addChild:spriteSheet];
eggAnimFrames = [NSMutableArray array];
for (int i = 1; i <= 10; i++)
{
[eggAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"%d.png", i]]];
}
rotateAnim = [CCAnimation animationWithFrames:eggAnimFrames delay:0.05f];
ball = [CCSprite spriteWithSpriteFrameName:@"1.png"];
ball.position=ccp(160,80);
rotateAction =[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:rotateAnim restoreOriginalFrame:YES]];
[spriteSheet addChild:ball];
Links tham khảo: http://www.raywenderlich.com/1271/how-to-use-animations-and-sprite-sheets-in-cocos2d