[一位菜鸟的COCOS-2D编程之路]精灵表单的制作以及简易动画的生成
1.第一步:使用Zwoptex 制作精灵表单
2.制作的表单的名称为 cocos2Dpng,cocos2D.plist;
3.精灵的动画效果 主要分为五部分。
// on "init" you need to initialize your instance -(id) init { // always call "super" init // Apple recommends to re-assign "self" with the "super's" return value if( (self=[super init]) ) { // ask director for the window size // //1将精灵帧纹理添加到精灵帧缓存中 [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"cocos2D.plist"]; //2创建一个精灵表单 CCSpriteBatchNode *batchNode = [CCSpriteBatchNode batchNodeWithFile:@"cocos2D.png"]; [self addChild:batchNode]; //穿件图片帧列表 NSMutableArray *animFrames = [NSMutableArray array]; for (int i = 1; i < 4; i ++) { CCSpriteFrame *temp = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"pandawalk%d.png",i]]; [animFrames addObject:temp]; } //4创建一个 动画对象 CCAnimation *walkAnim = [CCAnimation animationWithSpriteFrames:animFrames delay:0.1f]; //5创建精灵,运行动画动作 CGSize size = [[CCDirector sharedDirector] winSize]; CCSprite *panda = [CCSprite spriteWithSpriteFrameName:@"pandawalk1.png"]; panda.position = ccp(size.width*0.8, size.height*0.4); id walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim]]; [panda runAction:walkAction]; [panda runAction:[CCMoveTo actionWithDuration:6.0f position:ccp(size.width*0.2, size.height*0.4)]]; [batchNode addChild:panda]; } return self; }
效果图:
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步