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款超棒的单页面网站设计模板。关键是