Cocos2d学习之路三(使用Zwoptex创建精灵表单和CCAnimate动画)
生活随笔
收集整理的这篇文章主要介绍了
Cocos2d学习之路三(使用Zwoptex创建精灵表单和CCAnimate动画)
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
创建精灵表单:
创建动画先要把图片整合到一个图片上然后生成plist文件;
方法下载Zwoptex软件:http://www.zwopple.com/zwoptex/
然后打开选择 create new document
1把连续动画单独图片拖到窗口空白处;
2.现在图片是叠放在一起的 点击layout按钮
3. 修改图片大小 (默认很大,要修改成合适大小)
4.修改目录
点击工具栏的publish->publish Setting
把Texture File Path 和Coordinates Path 修改为任意目录
文件名要一至,我分别起的ya.plist 和ya.png
把Coordinates Format 改为Cocos2d 然后点击done
5. 点击publish 会生成对应的plist文件和png文件
6.拖到xcode中
在init方法中添加:
// 1.将精灵帧纹理添加到精灵帧缓存中[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"ya.plist"];//2. 创建一个精灵表单CCSpriteBatchNode *batchNode=[CCSpriteBatchNode batchNodeWithFile:@"ya.png"];[self addChild:batchNode];//3. 创建图片帧列表NSMutableArray *animFrames=[NSMutableArray array];for (int i=1; i<8; i++) {[animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"%d.png",i]]];}//创建动画对象CCAnimation *walkAnim=[[CCAnimation alloc] initWithSpriteFrames:animFrames delay:0.3];//创建精灵并进行动画动作CGSize winSize=[[CCDirector sharedDirector] winSize];CCSprite *panda=[CCSprite spriteWithSpriteFrameName:@"1.png"];panda.position=ccp(winSize.width*0.8, winSize.height*0.4);id walkAction=[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim]];[panda runAction:walkAction];[panda runAction:[CCMoveTo actionWithDuration:6.0f position:ccp(winSize.width*0.2, winSize.height*0.4)]];[batchNode addChild:panda];转载于:https://www.cnblogs.com/lixingle/p/3707693.html
总结
以上是生活随笔为你收集整理的Cocos2d学习之路三(使用Zwoptex创建精灵表单和CCAnimate动画)的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: php使用curl库进行ssl双向认证
- 下一篇: 推荐7款超棒的单页面网站设计模板。关键是