天天看點

cocos2d實作動畫效果

Vector<SpriteFrame *>allFrame;

    for(int i=0;i<4;i++)

    {char fname[20];

        sprintf(fname,"s_%d.png",i+1);

        SpriteFrame * sf=SpriteFrame::create(fname,Rect(0,0,200,250));

        allFrame.pushBack(sf);//把這一幀添加到集合

    }

    Animation * animation=Animation::createWithSpriteFrames(allFrame);

    animation->setDelayPerUnit(0.1);

    Animate * animate=Animate::create(animation);

    Sprite *spgirl=Sprite::create();

    spgirl->runAction(RepeatForever::create(animate));

        this->addChild(spgirl);

    spgirl->setPosition(Vec2(550,400));

    this->schedule(schedule_selector(HelloWorld::gameLogic),0.1);

       return true;

}

繼續閱讀