我是 iOS 开发新手。 我也开始学习Cocos2D了。
我已阅读本教程:http://www.raywenderlich.com/tutorials#cocos2d
对于初学者来说,这是一个极好的教程,但我也对图像动画感兴趣。我怎样才能完成动画?
所以我阅读了关于如何使用简单项目放置动画图像的教程(从上面的链接描述)。
在本教程中,我使用了 TexturePacker
并且它正在工作...但我想了解更多关于如何不使用 TexturePacker
为图像添加动画效果.
这可能吗?如果是这样,请解释如何操作或链接到如何使其工作的教程。
提前致谢。
最佳答案
您可以从文件运行动画。
CCSprite *coin = [CCSprite spriteWithFile:@"MyImage_1.png"];
coin.position = ccp(mS.width*0.5f, mS.height*0.5f);
[self addChild:coin z:2];
{
NSString *animationName = @"UNIQUE_ANIMATION_NAME";
CCAnimation* animation = nil;
animation = [[CCAnimationCache sharedAnimationCache] animationByName:animationName];
if(!animation)
{
NSMutableArray *animFrames = [NSMutableArray array];
for( int i=1;i<=5;i++)
{
NSString* path = [NSString stringWithFormat:@"MyImage_%d.png", i];
CCTexture2D* tex = [[CCTextureCache sharedTextureCache] addImage:path];
CGSize texSize = tex.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:tex rect:texRect];
[animFrames addObject:frame];
}
animation = [CCAnimation animationWithSpriteFrames:animFrames];
animation.delayPerUnit = 0.175f;
animation.restoreOriginalFrame = YES;
[[CCAnimationCache sharedAnimationCache] addAnimation:animation name:animationName];
}
if(animation)
{
CCAnimate *animAction = [CCAnimate actionWithAnimation:animation];
[coin runAction:animAction];
}
}
关于iphone - 如何在不使用TexturePacker的情况下在Cocos2D中添加动画图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17609439/