cocos2d-x 游戏中人物动态和剪切图片
来源:未知 责任编辑:责任编辑 发表时间:2013-11-18 20:56 点击:次
CCSize S=CCDirector::sharedDirector()->getWinSize();
p> //载入动画所需纹理图片
p>
p> CCTexture2D *texture=CCTextureCache::sharedTextureCache()->addImage("Blowfish0.png")
p> ;
p> //切图获取每一帧
p> CCSpriteFrame *frame0=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*0, 122*0, 160, 120));
p> CCSpriteFrame *frame1=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*0, 122*1, 160, 120));
p> CCSpriteFrame *frame2=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*1, 122*0, 160, 120));
p> CCSpriteFrame *frame3=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*1, 122*1, 160, 120));
p> CCSpriteFrame *frame4=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*2, 122*0, 160, 120));
p> CCSpriteFrame *frame5=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*2, 122*1, 160, 120));
p> CCSpriteFrame *frame6=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*0, 122*2, 160, 120));
p> CCSpriteFrame *frame7=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*0, 122*3, 160, 120));
p> CCSpriteFrame *frame8=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*1, 122*2, 160, 120));
p> CCSpriteFrame *frame9=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*1, 122*3, 160, 120));
p> CCSprite *sprite03=CCSprite::createWithSpriteFrame(frame0);
p> sprite03->setPosition(ccp(S.width/2+180,S.height/2-70+100*i));
p> sprite03->setScale((0.5+0.2*i));
p> addChild(sprite03,3,10+10*i);
p>
p>
p> CCArray *animFrames=CCArray::createWithCapacity(10);
p> animFrames->addObject(frame0);
p> animFrames->addObject(frame1);
p> animFrames->addObject(frame2);
p> animFrames->addObject(frame3);
p> animFrames->addObject(frame4);
p> animFrames->addObject(frame5);
p> animFrames->addObject(frame6);
p> animFrames->addObject(frame7);
p> animFrames->addObject(frame8);
p> animFrames->addObject(frame9);
p>
p> //定义每一帧和动画的间隔时间
p> CCAnimation *animation=CCAnimation::createWithSpriteFrames(animFrames,0.5);
p> //创建动画的Action
p> CCAnimate *animate=CCAnimate::create(animation);
p> CCActionInterval *seq=(CCActionInterval *)(CCSequence::create(animate,CCFlipX::create(false),animate->copy()->autorelease(),CCFlipX::create(false),NULL));
p> sprite03->runAction(CCRepeatForever::create(seq));
p> }
p>
p>}
p>
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>