加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2d-x-2.x与3.x帧动画实现方式的改变

发布时间:2020-12-14 17:02:27 所属栏目:百科 来源:网络整理
导读: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::createWithText

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;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读