2.x
//第二个参数表示显示区域的x,y,width,height frame0=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*0,237.5,191)); frame1=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*1,191)); frame2=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*2,191)); frame3=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*3,191)); Array *animFrames=Array::create(); animFrames->addobject(frame0); animFrames->addobject(frame1); animFrames->addobject(frame2); animFrames->addobject(frame3); //根据4幅帧生成CCAnimation对象 Animation *animation = Animation::createWithSpriteFrames(animFrames); //根据动画模板创建动画 animation->setDelayPerUnit(0.2f); //animFrames->release(); Animate *animate=Animate::create(animation);
3.x
Vector<SpriteFrame*> frameVec; SpriteFrame* frame = NULL; //用纹理创建4幅帧动画 SpriteFrame *frame0,*frame1,*frame2,*frame3; //第二个参数表示显示区域的x,191)); frameVec.pushBack(frame0); frameVec.pushBack(frame1); frameVec.pushBack(frame2); frameVec.pushBack(frame3); //根据4幅帧生成CCAnimation对象 Animation *animation = Animation::createWithSpriteFrames(frameVec); //根据动画模板创建动画 animation->setDelayPerUnit(0.2f); //animFrames->release(); Animate *animate=Animate::create(animation); return animate;
原文地址:https://www.jb51.cc/cocos2dx/339773.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。