Cocos2d学习之路三(使用Zwoptex创建精灵表单和CCAnimate动画)
生活随笔
收集整理的這篇文章主要介紹了
Cocos2d学习之路三(使用Zwoptex创建精灵表单和CCAnimate动画)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
創(chuàng)建精靈表單:
創(chuàng)建動(dòng)畫先要把圖片整合到一個(gè)圖片上然后生成plist文件;
方法下載Zwoptex軟件:http://www.zwopple.com/zwoptex/
然后打開(kāi)選擇 create new document?
1把連續(xù)動(dòng)畫單獨(dú)圖片拖到窗口空白處;
2.現(xiàn)在圖片是疊放在一起的 點(diǎn)擊layout按鈕
3. 修改圖片大小 ?(默認(rèn)很大,要修改成合適大小)
4.修改目錄
點(diǎn)擊工具欄的publish->publish Setting?
把Texture File Path 和Coordinates Path 修改為任意目錄 ??
文件名要一至,我分別起的ya.plist 和ya.png
把Coordinates Format 改為Cocos2d 然后點(diǎn)擊done?
5. 點(diǎn)擊publish 會(huì)生成對(duì)應(yīng)的plist文件和png文件
6.拖到xcode中
在init方法中添加:
// 1.將精靈幀紋理添加到精靈幀緩存中[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"ya.plist"];//2. 創(chuàng)建一個(gè)精靈表單CCSpriteBatchNode *batchNode=[CCSpriteBatchNode batchNodeWithFile:@"ya.png"];[self addChild:batchNode];//3. 創(chuàng)建圖片幀列表NSMutableArray *animFrames=[NSMutableArray array];for (int i=1; i<8; i++) {[animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"%d.png",i]]];}//創(chuàng)建動(dòng)畫對(duì)象CCAnimation *walkAnim=[[CCAnimation alloc] initWithSpriteFrames:animFrames delay:0.3];//創(chuàng)建精靈并進(jìn)行動(dòng)畫動(dòng)作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];轉(zhuǎn)載于:https://www.cnblogs.com/lixingle/p/3707693.html
總結(jié)
以上是生活随笔為你收集整理的Cocos2d学习之路三(使用Zwoptex创建精灵表单和CCAnimate动画)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: php使用curl库进行ssl双向认证
- 下一篇: 推荐7款超棒的单页面网站设计模板。关键是