cocos2d-x-2.x與3.x幀動畫實現方式的改變

2.x動畫

 //第二個參數表示顯示區域的x,y,width,height
    frame0=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*0,0,237.5, 191));
    frame1=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*1,0,237.5, 191));
    frame2=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*2,0,237.5, 191));
    frame3=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*3,0,237.5, 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,y,width,height
    frame0=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*0,0,237.5, 191));
    frame1=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*1,0,237.5, 191));
    frame2=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*2,0,237.5, 191));
    frame3=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*3,0,237.5, 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;
相關文章
相關標籤/搜索