cocos2d-x 游戏中人物动态和剪切图片
CCSize S=CCDirector::sharedDirector()->getWinSize();
//载入动画所需纹理图片
CCTexture2D *texture=CCTextureCache::sharedTextureCache()->addImage("Blowfish0.png")
;
//切图获取每一帧
CCSpriteFrame *frame0=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*0, 122*0, 160, 120));
CCSpriteFrame *frame1=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*0, 122*1, 160, 120));
CCSpriteFrame *frame2=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*1, 122*0, 160, 120));
CCSpriteFrame *frame3=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*1, 122*1, 160, 120));
CCSpriteFrame *frame4=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*2, 122*0, 160, 120));
CCSpriteFrame *frame5=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*2, 122*1, 160, 120));
CCSpriteFrame *frame6=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*0, 122*2, 160, 120));
CCSpriteFrame *frame7=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*0, 122*3, 160, 120));
CCSpriteFrame *frame8=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*1, 122*2, 160, 120));
CCSpriteFrame *frame9=CCSpriteFrame::createWithTexture(texture, CCRectMake(160*1, 122*3, 160, 120));
CCSprite *sprite03=CCSprite::createWithSpriteFrame(frame0);
sprite03->setPosition(ccp(S.width/2+180,S.height/2-70+100*i));
sprite03->setScale((0.5+0.2*i));
addChild(sprite03,3,10+10*i);
CCArray *animFrames=CCArray::createWithCapacity(10);
animFrames->addObject(frame0);
animFrames->addObject(frame1);
animFrames->addObject(frame2);
animFrames->addObject(frame3);
animFrames->addObject(frame4);
animFrames->addObject(frame5);
animFrames->addObject(frame6);
animFrames->addObject(frame7);
animFrames->addObject(frame8);
animFrames->addObject(frame9);
//定义每一帧和动画的间隔时间
CCAnimation *animation=CCAnimation::createWithSpriteFrames(animFrames,0.5);
//创建动画的Action
CCAnimate *animate=CCAnimate::create(animation);
CCActionInterval *seq=(CCActionInterval *)(CCSequence::create(animate,CCFlipX::create(false),animate->copy()->autorelease(),CCFlipX::create(false),NULL));
sprite03->runAction(CCRepeatForever::create(seq));
}
}
补充:移动开发 , 其他 ,